'这是输出......'
Loading C:\TEMP\BankDemo_mstest\Test_BankDemo\bin\Debug\Test_BankDemo.dll...
Starting execution...
Results Top Level Tests
------- ---------------
Error Test.BankDemo.AccountTest.CreditTest
Error Test.BankDemo.AccountTest.DebitTest
Error Test.BankDemo.AccountTest.FreezeTest
0/3 test(s) Passed, 3 Error
Summary
-------
Test Run Error.
Error 3
--------
Total 3
这是我使用的命令
OpenCover\OpenCover.Console.exe -register:user
-output:"Codecoverage.xml"
-mergebyhash
-target:"C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\MSTest.exe"
targetargs:"/testcontainer:
"C:\TEMP\BankDemo_mstest\Test_BankDemo\bin\Debug\Test_BankDemo.dll"
/noisolation"
-filter:"-[Bank.*]* +[Bank*]* +[Bank.Accounts*]* -[Test.BankDemo*]*"
ReportGenerator\bin\ReportGenerator.exe Codecoverage.xml Coverage HTML
(我什至尝试过 regsvr32 来注册配置文件并且我正在使用 XP)实际上我是 Nunit、mstest 和 opencoverage 的初学者,我在http://www.nunit.org/index.php?p=
找到了示例单元测试用例quickStart&r=2.4所以
** Nunit 测试类如下**
private TestContext testContextInstance;
public TestContext TestContext
{
get { return testContextInstance; }
set { testContextInstance = value; }
}
private int store;
[TestInitialize()]
public void TestFixtureSetUp()
{
store = 1;
}
上面的类与 Nunit 和 Opencoverage 一起工作正常,也显示了准确的数据,但是在替换 mstest 特定属性后相同的类没有工作,所以在发布这个问题后,我认为这个方法必须是静态的并添加了 TestContext 参数。所以我做了代码更改(粗体),如下和上面的命令工作正常。
MSTest 类
private TestContext testContextInstance;
public TestContext TestContext
{
get { return testContextInstance; }
set { testContextInstance = value; }
}
[ClassInitialize()]
public **static** void ClassInit(**TestContext context**)
{
}