所以我尝试使用mono,csharp和nunit设置项目。
我试图让测试运行,所以我构建了一个msbuild / xbuild Test.csproj
文件:
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<OutputType>Library</OutputType>
<OutputPath>bin</OutputPath>
<AssemblyName>Test</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="nunit.framework">
<HintPath>..\packages\NUnit\lib\net45\nunit.framework.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Test.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup>
<ProjectReference Include="..\mainproj.csproj">
<Name>Mainproj</Name>
</ProjectReference>
</ItemGroup>
</Project>
我使用xbuild Test.csproj
文件Test.cs
包含两个简单的测试:
使用NUnit.Framework;
namespace Foo.Test {
[TestFixture]
public class TestClass
{
[TestCase]
public void AddTest()
{
Assert.AreEqual(30, 15 + 15 );
}
[TestCase]
public void Minus()
{
Assert.AreEqual(30, 15 - 15 );
}
}
}
nunit-console4 bin/nunit.framework.dll bin/Test.dll
找不到任何测试:
NUnit version 2.4.8 Copyright (C) 2002-2007 Charlie Poole. Copyright (C) 2002-2004 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov. Copyright (C) 2000-2002 Philip Craig. All Rights Reserved. Runtime Environment - OS Version: Unix 15.0.0.0 CLR Version: 4.0.30319.17020 ( 4.2.1 (Stable 4.2.1.102/6dd2d0d Wed Dec 2 14:02:18 PST 2015) ) Tests run: 0, Failures: 0, Not run: 0, Time: 0.055 seconds
答案 0 :(得分:4)
为您的测试用例属性命名&#34;测试&#34; (不是&#34; TestCase&#34;):
using NUnit.Framework;
namespace Foo.Test {
[TestFixture ()]
public class TestClass
{
[Test ()]
public void AddTest()
{
Assert.AreEqual(30, 15 + 15 );
}
[Test ()]
public void Minus()
{
Assert.AreEqual(30, 15 - 15 );
}
}
}
$>nunit-console4 Test.dll
NUnit version 2.4.8
~~~~
..F
Tests run: 2, Failures: 1, Not run: 0, Time: 0.120 seconds
Test Case Failures:
1) Foo.Test.TestClass.Minus : Expected: 30
注意:没有理由将nunit.framework.dll
传递给nunit-console4
,因为它会被扫描进行没有任何测试的测试。