Nunit runs each test twice

2019-06-19 07:42发布

I encounter a problem running my tests via NUnit. I dont know why but each test runs twice. The point is that on another laptop it normally runs only one time.

Have anyone the same problem and know how to deal with it?

6条回答
等我变得足够好
2楼-- · 2019-06-19 08:17

In case you put the *.dll twice, the test get double executed.

Seen on NUnit.3.10.1, nunit3-console 3.9.0

Example:

nunit3-console myTestDll.dll --test=MyNameSpace.Test myTestDll.dll** --result=myResult.xml

查看更多
萌系小妹纸
3楼-- · 2019-06-19 08:23

In my case, it was having a base class and a derived class both having the TestFixture Attribute. All tests from the derived class would run twice.

Fixed it by only putting attribute on base class.

查看更多
做自己的国王
4楼-- · 2019-06-19 08:25

I had a similar problem where running the test with the Visual Studio NUnit3 runner, the test would run only once but when running in the command line with NUnit3-Command.exe, the test would run twice. I spent way too long chasing this down. I noticed that the command line runner was reporting 2 tests were run and came to the conclusion it was an issue in the dll. This may sound crazy but I copied all my test code into a new class, deleted the old, compiled and the test now runs just once in both scenarios.

查看更多
一夜七次
5楼-- · 2019-06-19 08:25

The problem typically arises when you load a test container (.dll) multiple times.

This can happen if you load the test containers from a root floder that has both bin and obj folders inside, which is a typical setup of Visual Studio projects.

Try to limit your test container loading from the bin folders.

查看更多
迷人小祖宗
6楼-- · 2019-06-19 08:26

The running of test can also be duplicated is when sequential tests accidentally have the same test parameters.

 [Test, Sequential]
            public void Integr_MController_DeleteGet_ReturnsViewAndModel(
 [Values("Do@london.com", "Do@london.com")] string firstEmail,


 [Values("Zyg@london.com", "Zyg@london.com")] HTTPstring updatedEmail) {test code}

Will run the same test twice and will show up in TestExplorer as the same test.

查看更多
孤傲高冷的网名
7楼-- · 2019-06-19 08:29

I had the same problem. In my case, I had both the Visual Studio extension and the NuGet package of the NUnit Test Runner installed. It seems they were both executing the tests, resulting in tests being run twice.

Uninstalling the Visual Studio extension solved the issue.

查看更多
登录 后发表回答