Jared
Jared

Reputation: 6025

Is it possible to have multiple 'TestClass'es in MSTest?

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

Answers (7)

Dov
Dov

Reputation: 1

try clean the search text in Test Explorer.

Upvotes: 0

Neh18
Neh18

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

Ger Hobbelt
Ger Hobbelt

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

Vanof
Vanof

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

Jared
Jared

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

ChrisLively
ChrisLively

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

AJ.
AJ.

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

Related Questions