I am currently building a sample application where I use MS Test to implement a Scenario-based Given-When-Then-style UnitTest-project in VS2012. For this to work I have an abstract Scenario (base) class that has virtual Given()- and When()-methods that are run during the TestInitialization-phase. The results of the When()-method are then stored and can be verified using arbitrary TestMethods in any concrete Scenario-class, representing the 'Then'-statements. This all works perfectly.
There's one more thing I'd like to control, though: the names of all the TestMethods as they are shown in the TestExplorer of Visual Studio. This is because many TestMethods have the same or similar names, but are executed in different scenario's (such as 'ExpectedExceptionIsThrown'). I would have thought such a thing would be supported by MS Test, perhaps by native support of the TestMethodAttribute like so:
[TestMethod("DisplayName here...")]
public void ThenThisShouldHappen()
{
...
}
I've looked through the API of MS Test but can't seem to find any way to do this. Is this at all possible with MS Test?
The TestClass attribute denotes a class that contains unit tests. The TestMethod attribute indicates a method is a test method.
Run tests in Test Explorer If Test Explorer is not visible, choose Test on the Visual Studio menu, choose Windows, and then choose Test Explorer (or press Ctrl + E, T). As you run, write, and rerun your tests, the Test Explorer displays the results in a default grouping of Project, Namespace, and Class.
@After annotation is used on a method containing java code to run after each test case.
TestInitialize and TestCleanup are ran before and after each test, this is to ensure that no tests are coupled. If you want to run methods before and after ALL tests, decorate relevant methods with the ClassInitialize and ClassCleanup attributes. Save this answer.
I was struggling with this concept for awhile myself until I realize that you can right-click the Test Explorer area and choose Group By -> Class.
This isn't perfect by all means, but coupled with all of the functionality available with test playlists and/or Resharper, it is possible to customize your Test experience a bit.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With