XUnit跳过所有测试。

10

我在使用xunit时遇到了问题,它会跳过所有测试而不显示任何消息或错误。我正在使用Ubuntu 20.04,但在Windows 10上也遇到了相同的问题。

michael@michael-System-Product-Name:~/gradebook$ cd test
michael@michael-System-Product-Name:~/gradebook/test$ mkdir GradeBook.Test
michael@michael-System-Product-Name:~/gradebook/test$ cd GradeBook.Test
michael@michael-System-Product-Name:~/gradebook/test/GradeBook.Test$ sudo dotnet new xunit
[sudo] password for michael: 
Getting ready...
The template "xUnit Test Project" was created successfully.

Processing post-creation actions...
Running 'dotnet restore' on /home/michael/gradebook/test/GradeBook.Test/GradeBook.Test.csproj...
  Determining projects to restore...
  Restored /home/michael/gradebook/test/GradeBook.Test/GradeBook.Test.csproj (in 548 ms).
Restore succeeded.

michael@michael-System-Product-Name:~/gradebook/test/GradeBook.Test$ sudo dotnet test
  Determining projects to restore...
  All projects are up-to-date for restore.
  GradeBook.Test -> /home/michael/gradebook/test/GradeBook.Test/bin/Debug/net5.0/GradeBook.Test.dll
Test run for /home/michael/gradebook/test/GradeBook.Test/bin/Debug/net5.0/GradeBook.Test.dll (.NETCoreApp,Version=v5.0)
Microsoft (R) Test Execution Command Line Tool Version 16.8.3
Copyright (c) Microsoft Corporation.  All rights reserved.

Starting test execution, please wait...
A total of 1 test files matched the specified pattern.

Passed!  - Failed:     0, Passed:     1, Skipped:     0, Total:     1, Duration: 1 ms - /home/michael/gradebook/test/GradeBook.Test/bin/Debug/net5.0/GradeBook.Test.dll (net5.0)

1
那并没有跳过任何测试 - 它运行了1个测试,通过了。(我怀疑你为什么要使用sudo来运行dotnet new。) - Jon Skeet
@jonskeet 无论我在这个测试中写了什么,都会通过(跳过),即使条件不可能满足,比如3等于5,我使用sudo因为到目前为止没有任何效果:( - Michal G
“Passes”和“skips”根本不是一回事。你的输出清楚地显示没有测试被跳过,而有一个测试通过了——这是我所期望的,因为你刚刚创建了一个新的测试项目。你没有展示一个失败的测试,或者任何编辑测试的迹象。请花些时间澄清你的问题。 - Jon Skeet
@jonskeet 噢...我太匆忙发布了这个帖子,你是对的,抱歉给你添麻烦了。我遇到了很多JUnit问题,以为这个也一样。 - Michal G
2
虽然很简单,但我也犯了完全相同的阅读理解错误。幸运的是,这是“xunit跳过所有测试”的第一个谷歌搜索结果。感谢大家。 - brendanrichards
显示剩余3条评论
1个回答

46

曾经去过那里,做过那件事。这只是一种视觉错觉 :)

Passed!  - Failed:     0, Passed:     1, Skipped:     0, Total:     1, ...

再试着读一遍那行。它说通过了!而通过的测试数是1。跳过的测试数实际上是0。只不过我们的眼睛看到靠在一起的东西就会自动联想。


5
这太可怕了,哈哈。 - justin.m.chase
1
我中计了... - Nomnom
1
我觉得我们需要在这里加一个计数器。我也掉进了这个坑里:D - Paul Marshall
1
我讨厌我的生活。 - Richard Avenia

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接