Add some unit tests
This commit is contained in:
Родитель
5e122d9267
Коммит
87f4da5d36
|
@ -12,6 +12,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
|
|||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "v2-test-assembly", "src\v2-test-assembly\v2-test-assembly.csproj", "{B6D3AEAE-ECDA-4047-A9BA-CC6DA3EBEDF8}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "nunit.v2.driver.tests", "src\nunit.v2.driver.tests\nunit.v2.driver.tests.csproj", "{10659B84-B1DA-4768-9AB7-CDA3EB58EFD4}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
|
@ -26,6 +28,10 @@ Global
|
|||
{B6D3AEAE-ECDA-4047-A9BA-CC6DA3EBEDF8}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{B6D3AEAE-ECDA-4047-A9BA-CC6DA3EBEDF8}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{B6D3AEAE-ECDA-4047-A9BA-CC6DA3EBEDF8}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{10659B84-B1DA-4768-9AB7-CDA3EB58EFD4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{10659B84-B1DA-4768-9AB7-CDA3EB58EFD4}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{10659B84-B1DA-4768-9AB7-CDA3EB58EFD4}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{10659B84-B1DA-4768-9AB7-CDA3EB58EFD4}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("nunit.v2.driver.tests")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("nunit.v2.driver.tests")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2016")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("10659b84-b1da-4768-9ab7-cda3eb58efd4")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
|
@ -0,0 +1,153 @@
|
|||
using System;
|
||||
using System.Reflection;
|
||||
using NUnit.Core;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace NUnit.Engine.Drivers.Tests
|
||||
{
|
||||
public class TestEventAdapterTests : ITestEventListener
|
||||
{
|
||||
private EventListener _eventAdapter;
|
||||
private string _report;
|
||||
|
||||
private static TestName _testName = new TestName()
|
||||
{
|
||||
RunnerID = RUNNER_ID,
|
||||
TestID = new TestID(TEST_ID),
|
||||
Name = TEST_NAME,
|
||||
FullName = FULL_NAME
|
||||
};
|
||||
|
||||
private const int RUNNER_ID = 42;
|
||||
private const int TEST_ID = 9999;
|
||||
private const string TEST_NAME = "TestName";
|
||||
private const string FULL_NAME = "FullName";
|
||||
|
||||
[SetUp]
|
||||
public void Initialize()
|
||||
{
|
||||
_eventAdapter = new TestEventAdapter(this);
|
||||
_report = null;
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RunStartedIsIgnored()
|
||||
{
|
||||
_eventAdapter.RunStarted("Dummy", 99);
|
||||
Assert.Null(_report, "No report should be received");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RunFinishedIsIgnored()
|
||||
{
|
||||
_eventAdapter.RunFinished(new TestResult(new TestName()));
|
||||
Assert.Null(_report, "No report should be received");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RunFinishedExceptionIsIgnored()
|
||||
{
|
||||
_eventAdapter.RunFinished(new Exception("Error!"));
|
||||
Assert.Null(_report, "No report should be received");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SuiteStarted()
|
||||
{
|
||||
var suite = new FakeTestSuite(RUNNER_ID, TEST_ID, TEST_NAME, FULL_NAME);
|
||||
_eventAdapter.SuiteStarted(suite.TestName);
|
||||
string expected = string.Format("<start-suite id=\"{0}-{1}\" name=\"{2}\" fullname=\"{3}\"/>", RUNNER_ID, TEST_ID, TEST_NAME, FULL_NAME);
|
||||
Assert.That(_report, Is.EqualTo(expected));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestStarted()
|
||||
{
|
||||
var test = new FakeTestCase(RUNNER_ID, TEST_ID, TEST_NAME, FULL_NAME);
|
||||
_eventAdapter.TestStarted(test.TestName);
|
||||
string expected = string.Format("<start-test id=\"{0}-{1}\" name=\"{2}\" fullname=\"{3}\"/>", RUNNER_ID, TEST_ID, TEST_NAME, FULL_NAME);
|
||||
Assert.That(_report, Is.EqualTo(expected));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SuiteFinished()
|
||||
{
|
||||
var suite = new FakeTestSuite(RUNNER_ID, TEST_ID, TEST_NAME, FULL_NAME, 1234);
|
||||
var result = new TestResult(suite);
|
||||
result.SetResult(ResultState.Failure, "Something failed!", null);
|
||||
result.AssertCount = 9999;
|
||||
result.Time = 12.5;
|
||||
_eventAdapter.SuiteFinished(result);
|
||||
string expected = string.Format(
|
||||
"<test-suite type=\"TestSuite\" id=\"{0}-{1}\" name=\"{2}\" fullname=\"{3}\" runstate=\"Runnable\" testcasecount=\"1234\" result=\"Failed\" duration=\"12.500000\" total=\"1234\" passed=\"0\" failed=\"0\" inconclusive=\"0\" skipped=\"0\" asserts=\"9999\"><failure><message><![CDATA[Something failed!]]></message></failure></test-suite>",
|
||||
RUNNER_ID, TEST_ID, TEST_NAME, FULL_NAME);
|
||||
Assert.That(_report, Is.EqualTo(expected));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestFinished()
|
||||
{
|
||||
var test = new FakeTestCase(RUNNER_ID, TEST_ID, TEST_NAME, FULL_NAME);
|
||||
var result = new TestResult(test);
|
||||
result.SetResult(ResultState.Failure, "MESSAGE", "STACKTRACE");
|
||||
result.Time = 1.234;
|
||||
result.AssertCount = 5;
|
||||
_eventAdapter.TestFinished(result);
|
||||
string expected =
|
||||
string.Format("<test-case id=\"{0}-{1}\" name=\"{2}\" fullname=\"{3}\" methodname=\"FakeTestMethod\" classname=\"{4}\" runstate=\"Runnable\" result=\"Failed\" duration=\"1.234000\" asserts=\"5\"><failure><message><![CDATA[MESSAGE]]></message><stack-trace><![CDATA[STACKTRACE]]></stack-trace></failure></test-case>",
|
||||
RUNNER_ID, TEST_ID, TEST_NAME, FULL_NAME, typeof(FakeTestCase).FullName);
|
||||
Assert.That(_report, Is.EqualTo(expected));
|
||||
}
|
||||
|
||||
#region ITestEventListener Implementation
|
||||
|
||||
public void OnTestEvent(string report)
|
||||
{
|
||||
_report = report;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Nested Fake Test Classes
|
||||
|
||||
private class FakeTestCase : TestMethod
|
||||
{
|
||||
public FakeTestCase(int runnerID, int testID, string name, string fullname)
|
||||
: base(typeof(FakeTestCase).GetMethod("FakeTestMethod", BindingFlags.NonPublic | BindingFlags.Instance))
|
||||
{
|
||||
TestName.RunnerID = runnerID;
|
||||
TestName.TestID = new TestID(testID);
|
||||
TestName.Name = name;
|
||||
TestName.FullName = fullname;
|
||||
}
|
||||
|
||||
private void FakeTestMethod() { }
|
||||
}
|
||||
|
||||
private class FakeTestSuite : TestSuite
|
||||
{
|
||||
private int _testCaseCount;
|
||||
|
||||
public FakeTestSuite(int runnerID, int testID, string name, string fullname)
|
||||
: this(runnerID, testID, name, fullname, 0) { }
|
||||
|
||||
public FakeTestSuite(int runnerID, int testID, string name, string fullname, int testCaseCount)
|
||||
: base(name)
|
||||
{
|
||||
TestName.RunnerID = runnerID;
|
||||
TestName.TestID = new TestID(testID);
|
||||
TestName.Name = name;
|
||||
TestName.FullName = fullname;
|
||||
|
||||
_testCaseCount = testCaseCount;
|
||||
}
|
||||
|
||||
public override int TestCount
|
||||
{
|
||||
get { return _testCaseCount; }
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -0,0 +1,77 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{10659B84-B1DA-4768-9AB7-CDA3EB58EFD4}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>NUnit.Engine.Drivers.Tests</RootNamespace>
|
||||
<AssemblyName>nunit.v2.driver.tests</AssemblyName>
|
||||
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="nunit.core, Version=2.6.4.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\extension\lib\nunit.core.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="nunit.core.interfaces">
|
||||
<HintPath>..\extension\lib\nunit.core.interfaces.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="nunit.engine.api, Version=3.0.0.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\packages\NUnit.Engine.Api.3.5.0-dev-03131\lib\nunit.engine.api.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="nunit.framework, Version=3.4.1.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\packages\NUnit.3.4.1\lib\net20\nunit.framework.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="NUnit.System.Linq, Version=0.2.0.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\packages\NUnit.3.4.1\lib\net20\NUnit.System.Linq.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="TestEventAdapterTests.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\extension\nunit.v2.driver.csproj">
|
||||
<Project>{379058e2-e834-4cc7-b5cd-ac8dfcf82aea}</Project>
|
||||
<Name>nunit.v2.driver</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
|
@ -0,0 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="NUnit" version="3.4.1" targetFramework="net20" />
|
||||
<package id="NUnit.Engine.Api" version="3.5.0-dev-03131" targetFramework="net20" />
|
||||
</packages>
|
Загрузка…
Ссылка в новой задаче