Reputation: 6025
I'm trying to write unit tests in MSTest and I've created two TestClasses. When I look at the Test List Editor, the only tests that are shown are the ones that appear in one of the classes.
I can't figure out how to get tests from both of these classes to run. Any ideas?
Upvotes: 2
Views: 2015
Reputation: 172
If your Classes and Methods are public only then it will be viewed in Test explorer. I faced same issue which was removed only when i apply public keyword in front of Class and Method.
[TestClass]
public class Class1
{
[TestMethod]
public void Method1()
{
}}
Upvotes: 2
Reputation: 1188
(For the next one who arrives here via google looking for answers)
In my case, none of the above applied.
The key element to make all test files (and the classes therein) show up in the Test Explorer (VS2019) was adding the public
keyword to each test class. Didn't need it before with Nunit, but we moved to MSTest and then the tests disappeared. Adding public
made them show up again:
[TestClass]
public class TestBibTeX // <-- +public+
{
...
Upvotes: 5
Reputation: 124
We have two test projects in a solution and the test list shows all tests from both projects.
I remember that I encountered this issue in the past where some test methods were missing from the test list and i suspect that it has to do whith the bug concerning the .vsdmi files. It can happen if your working with source control and allow multiple check out.
Make sure that: All your test classes have the proper attribute. All your methods have the proper attribute.
If it still happens backup you .vsdmi file put it somewhere else and delete the one(s) that are in your project tree (most likely the root). Then close and reopen your project/solution and hit Test/Window/Test View...
Hope this helps!
Upvotes: 0
Reputation: 6025
It seemed like cleaning the solution, closing Visual Studio, deleting all the TestResults, deleting the .vsmdi file, and deleting the .ncb file and rebuilding the solution have fixed the problem.
Upvotes: 0
Reputation: 88064
We have hundreds of test cases in some of our projects. It's not only possible, but essential. Most likely you are missing attributes on the class and/or methods of your test class.
Upvotes: 2
Reputation: 16719
Yes, it is definitely possible, and it's odd that all of your tests aren't showing up. Do both of your test classes have the [TestClass()] attribute?
Upvotes: 1