简体   繁体   中英

Running multiple Unit Tests in an unit test project

I am currently working on a project using C# and Visual Studio 2012.

It is not detected via the Test Explorer, the "Not Run" test does not include the file.

Solution
    MainProject
        ProjectA.Tests (that is the project)
           UnitTestsA.cs (Actually run)
           UnitTestsB.cs (Neven run)

I was having this problem, but just figured out a solution.

I am building a .NET Core library for use in a DotNet console app. There is a separate solution for the library. The library contains projects for the library, a unit test project, and a showcase project.

I followed the steps in these articles:

I added some extra library classes in the library, and I made sure to change the package version for the lbirary. I rebuilt the library, and published it to NuGET.

I added an extra class in the test project, and could not get the routine in the test class to run. I had followed these steps: - Added a regular C# class to the test project - Added [TestClass] at the top of the class - Added a public void method, and added [TestMethod] above it - Used manage NuGET projects on the test project, and made sure I updated to the latest version of the library package

But "Run All" was not seeing the extra test.

I finally discovered that the new testing class needed to be declared as public! Then the next Run All properly picked up the extra test method in the new test class.

Here is an outline of the necessary things in the extra testing class:

using System;
using UtilityLib.APIDir;

namespace UtilityLibTest
{
   [TestClass]
   public class UnitTest_NewAPI
   {
       [TestMethod]
       public void TestNewAPI()
       {
          NewAPI tester = new NewAPI();
          bool someResult = tester.DoSomething();
       }
   }
}

Other comments on Visual Studio projects:

There are several issues with Visual Studio, where shutting down all copies of Visual Studio, and restarting, can fix problems.

When I created my first .Net core lib project, published it to NuGET, and then used NuGET to load it into another project, but I was unable to reference the classes within the library. I started looking into some tools to try to look into the NuGET package.

But after system restart (For an entirely unrelated issue), I restarted Visual Studio, and then I was able to access the library classes from my main project.

Another issue is from a project that consumes a nuget library, sometimes after updating the version of the assembly with nuget, the calling program might not be able to access the namespaces or classes in the updated library. A rebuild all on the calling project fixed that problem for me yesterday.

In order for Visual Studio to recognize your unit tests, you need to rebuild the unit test project. It is possible that the unit test project is not set to build as part of your current build configuration and thus is not being built when you build the solution.

I finally figured out my problem. I think most people encounter this problem same as me. The root problem is that I add the unit test class in the wrong way. Try to re-add the file using the "Test" section. This would make the class get dependency to the project. Otherwise, the project did not include it when running test.

if you just add 2nd C# class file to manage your 2nd set of test code in single unit test project, make sure those things happen.

  1. <\/li><\/ol>

    1. <\/li><\/ol>

      something like this shall help在此处输入图像描述<\/a>

      "

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM