不确定我在尝试使用 opencover 时做错了什么。我可以通过针对可执行控制台应用程序运行它来生成报告,但是每当我尝试针对实际测试代码运行它时,我都不走运。我已将 mstest 和 opencover 添加到系统路径中。
图书馆代码:
namespace SimpleLibrary
{
public class SimpleClass
{
public string HelloWorld()
{
return "HelloWorld!";
}
}
}
测试代码:
namespace SimpleTestProj
{
[TestClass()]
public class SimpleClassTest
{
[TestMethod()]
public void HelloWorldTest()
{
SimpleClass target = new SimpleClass();
string expected = "HelloWorld!";
string actual;
actual = target.HelloWorld();
Assert.AreEqual(expected, actual);
}
}
}
使用 '-register:user' 标志,测试由于某种原因而失败:
C:\nickolay\SimpleLibrary\SimpleTestProj\bin\Release>opencover.console.exe -output:"coverage.xml" -mergebyhash -target:
"mstest.exe" -targetdir:"C:\nickolay\SimpleLibrary\SimpleTestProj\bin\Release" -targetargs:"/testcontainer:SimpleTestPro
j.dll" -filter:+[*]* -register:user
Executing: C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\mstest.exe
Microsoft (R) Test Execution Command Line Tool Version 10.0.30319.1
Copyright (c) Microsoft Corporation. All rights reserved.
Loading SimpleTestProj.dll...
Starting execution...
Results Top Level Tests
------- ---------------
Failed SimpleTestProj.SimpleClassTest.HelloWorldTest
0/1 test(s) Passed, 1 Failed
Summary
-------
Test Run Failed.
Failed 1
---------
Total 1
Results file: C:\nickolay\SimpleLibrary\SimpleTestProj\bin\Release\TestResults\labuser.SDKiosk_SAN-D5RHRCK1 2013-07-24
21_04_25.trx
Test Settings: Default Test Settings
Committing...
Visited Classes 0 of 2 (0)
Visited Methods 0 of 4 (0)
Visited Points 0 of 9 (0)
Visited Branches 0 of 4 (0)
==== Alternative Results (includes all methods including those without corresponding source) ====
Alternative Visited Classes 0 of 2 (0)
Alternative Visited Methods 0 of 6 (0)
如果没有“-register:user”,则表示程序集未检测:
C:\nickolay\SimpleLibrary\SimpleTestProj\bin\Release>opencover.console.exe -output:"coverage.xml" -mergebyhash -target:
"mstest.exe" -targetdir:"C:\nickolay\SimpleLibrary\SimpleTestProj\bin\Release" -targetargs:"/testcontainer:SimpleTestPro
j.dll" -filter:+[*]*
Executing: C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\mstest.exe
Microsoft (R) Test Execution Command Line Tool Version 10.0.30319.1
Copyright (c) Microsoft Corporation. All rights reserved.
Loading SimpleTestProj.dll...
Starting execution...
Results Top Level Tests
------- ---------------
Passed SimpleTestProj.SimpleClassTest.HelloWorldTest
1/1 test(s) Passed
Summary
-------
Test Run Completed.
Passed 1
---------
Total 1
Results file: C:\nickolay\SimpleLibrary\SimpleTestProj\bin\Release\TestResults\labuser.SDKiosk_SAN-D5RHRCK1 2013-07-24
21_08_43.trx
Test Settings: Default Test Settings
Committing...
No results - no assemblies that matched the supplied filter were instrumented
this could be due to missing PDBs for the assemblies that match the filter
please review the output file and refer to the Usage guide (Usage.rtf)
Mstest 从目录成功运行:
C:\nickolay\SimpleLibrary\SimpleTestProj\bin\Release>mstest /testcontainer:SimpleTestProj.dll
Microsoft (R) Test Execution Command Line Tool Version 10.0.30319.1
Copyright (c) Microsoft Corporation. All rights reserved.
Loading SimpleTestProj.dll...
Starting execution...
Results Top Level Tests
------- ---------------
Passed SimpleTestProj.SimpleClassTest.HelloWorldTest
1/1 test(s) Passed
Summary
-------
Test Run Completed.
Passed 1
---------
Total 1
Results file: C:\nickolay\SimpleLibrary\SimpleTestProj\bin\Release\TestResults\labuser.SDKiosk_SAN-D5RHRCK1 2013-07-24
21_11_00.trx
Test Settings: Default Test Settings
我的头已经厌倦了在这里被撞到墙上,感谢您的帮助。