Skip to content

Commit

Permalink
Merge pull request #25 from nunit/issue-17
Browse files Browse the repository at this point in the history
Add tests to verify that #17 is fixed; cateorize tests by expected result
  • Loading branch information
CharliePoole committed May 16, 2015
2 parents 43795cc + eb1949e commit 2782be4
Show file tree
Hide file tree
Showing 12 changed files with 116 additions and 36 deletions.
6 changes: 6 additions & 0 deletions demo/NUnitTestDemo/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="test.setting" value="54321"/>
</appSettings>
</configuration>
18 changes: 9 additions & 9 deletions demo/NUnitTestDemo/AsyncTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,67 +7,67 @@ namespace NUnitTestDemo
{
public class AsyncTests
{
[Test]
[Test, ExpectPass]
public async void AsyncVoidTestSucceeds()
{
var result = await ReturnOne();

Assert.AreEqual(1, result);
}

[Test]
[Test, ExpectFailure]
public async void AsyncVoidTestFails()
{
var result = await ReturnOne();

Assert.AreEqual(2, result);
}

[Test]
[Test, ExpectError]
public async void AsyncVoidTestThrowsException()
{
await ThrowException();

Assert.Fail("Should never get here");
}

[Test]
[Test, ExpectPass]
public async Task AsyncTaskTestSucceeds()
{
var result = await ReturnOne();

Assert.AreEqual(1, result);
}

[Test]
[Test, ExpectFailure]
public async Task AsyncTaskTestFails()
{
var result = await ReturnOne();

Assert.AreEqual(2, result);
}

[Test]
[Test, ExpectError]
public async Task AsyncTaskTestThrowsException()
{
await ThrowException();

Assert.Fail("Should never get here");
}

[TestCase(ExpectedResult = 1)]
[TestCase(ExpectedResult = 1), ExpectPass]
public async Task<int> AsyncTaskWithResultSucceeds()
{
return await ReturnOne();
}

[TestCase(ExpectedResult = 2)]
[TestCase(ExpectedResult = 2), ExpectFailure]
public async Task<int> AsyncTaskWithResultFails()
{
return await ReturnOne();
}

[TestCase(ExpectedResult = 0)]
[TestCase(ExpectedResult = 0), ExpectError]
public async Task<int> AsyncTaskWithResultThrowsException()
{
return await ThrowException();
Expand Down
25 changes: 25 additions & 0 deletions demo/NUnitTestDemo/ConfigFileTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System;
using System.Configuration;
using System.IO;
using NUnit.Framework;

namespace NUnitTestDemo
{
[ExpectPass]
public class ConfigFileTests
{
[Test]
public static void ProperConfigFileIsUsed()
{
var expectedPath = Path.Combine(TestContext.CurrentContext.TestDirectory, "NUnit3TestDemo.dll.config");
Assert.That(expectedPath, Is.EqualTo(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile));
}

[Test]
public static void CanReadConfigFile()
{
Assert.That(ConfigurationManager.AppSettings.Get("test.setting"), Is.EqualTo("54321"));
}

}
}
40 changes: 40 additions & 0 deletions demo/NUnitTestDemo/ExpetedOutcomeAttributes.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NUnit.Framework;

namespace NUnitTestDemo
{
public class ExpectPassAttribute : PropertyAttribute
{
public ExpectPassAttribute() : base("Expect", "Pass") { }
}


public class ExpectFailureAttribute : PropertyAttribute
{
public ExpectFailureAttribute() : base("Expect", "Failure") { }
}

public class ExpectIgnoreAttribute : PropertyAttribute
{
public ExpectIgnoreAttribute() : base("Expect", "Ignore") { }
}

public class ExpectErrorAttribute : PropertyAttribute
{
public ExpectErrorAttribute() : base("Expect", "Error") { }
}

public class ExpectInconclusiveAttribute : PropertyAttribute
{
public ExpectInconclusiveAttribute() : base("Expect", "Inconclusive") { }
}

public class ExpectMixedAttribute : PropertyAttribute
{
public ExpectMixedAttribute() : base("Expect", "Mixed") { }
}
}
3 changes: 2 additions & 1 deletion demo/NUnitTestDemo/GenericTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ namespace NUnitTestDemo
[TestFixture(typeof(int))]
public class GenericTests<T>
{
[Test]
[Test, ExpectPass]
public void TestIt() { }
}

[ExpectPass]
[TestFixture(typeof(ArrayList))]
[TestFixture(typeof(List<int>))]
public class GenericTests_IList<TList> where TList : IList, new()
Expand Down
6 changes: 5 additions & 1 deletion demo/NUnitTestDemo/NUnit3TestDemo.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,24 +41,28 @@
<HintPath>..\packages\NUnit.3.0.0-beta-2\lib\net45\nunit.framework.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="AsyncTests.cs" />
<Compile Include="ConfigFileTests.cs" />
<Compile Include="ExpetedOutcomeAttributes.cs" />
<Compile Include="GenericTests.cs" />
<Compile Include="TextOutputTests.cs" />
<Compile Include="ParameterizedTests.cs" />
<Compile Include="SetUpFixtureTests.cs" />
<Compile Include="SimpleTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TestFixtureSetUpTests.cs" />
<Compile Include="OneTimeSetUpTests.cs" />
<Compile Include="Theories.cs" />
</ItemGroup>
<ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace NUnitTestDemo
{
[TestFixture]
[TestFixture, ExpectPass]
public class OneTimeSetUpTests
{
int SetUpCount;
Expand Down
17 changes: 10 additions & 7 deletions demo/NUnitTestDemo/ParameterizedTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace NUnitTestDemo
{
public class ParameterizedTests
{
[ExpectPass]
[TestCase(2, 2, 4)]
[TestCase(0, 5, 5)]
[TestCase(31, 11, 42)]
Expand All @@ -15,6 +16,7 @@ public void TestCaseSucceeds(int a, int b, int sum)
Assert.That(a + b, Is.EqualTo(sum));
}

[ExpectPass]
[TestCase(2, 2, ExpectedResult = 4)]
[TestCase(0, 5, ExpectedResult = 5)]
[TestCase(31, 11, ExpectedResult = 42)]
Expand All @@ -23,48 +25,49 @@ public int TestCaseSucceeds_Result(int a, int b)
return a + b;
}

[ExpectFailure]
[TestCase(31, 11, 99)]
public void TestCaseFails(int a, int b, int sum)
{
Assert.That(a + b, Is.EqualTo(sum));
}

[TestCase(31, 11, ExpectedResult = 99)]
[TestCase(31, 11, ExpectedResult = 99), ExpectFailure]
public int TestCaseFails_Result(int a, int b)
{
return a + b;
}

[TestCase(31, 11)]
[TestCase(31, 11), ExpectInconclusive]
public void TestCaseIsInconclusive(int a, int b)
{
Assert.Inconclusive("Inconclusive test case");
}

[Ignore("Ignored test")]
[Ignore("Ignored test"), ExpectIgnore]
[TestCase(31, 11)]
public void TestCaseIsIgnored_Attribute(int a, int b)
{
}

[TestCase(31, 11, Ignore = "Ignoring this")]
[TestCase(31, 11, Ignore = "Ignoring this"), ExpectIgnore]
public void TestCaseIsIgnored_Property(int a, int b)
{
}

[TestCase(31, 11)]
[TestCase(31, 11), ExpectIgnore]
public void TestCaseIsIgnored_Assert(int a, int b)
{
Assert.Ignore("Ignoring this test case");
}

[TestCase(31, 11)]
[TestCase(31, 11), ExpectError]
public void TestCaseThrowsException(int a, int b)
{
throw new Exception("Exception from test case");
}

[TestCase(42, TestName="AlternateTestName")]
[TestCase(42, TestName="AlternateTestName"), ExpectPass]
public void TestCaseWithAlternateName(int x)
{
}
Expand Down
4 changes: 2 additions & 2 deletions demo/NUnitTestDemo/SetUpFixtureTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public void AfterTests()
}
}

[TestFixture]
[TestFixture, ExpectPass]
public class TestFixture1
{
[Test]
Expand All @@ -37,7 +37,7 @@ public void Test1()
}
}

[TestFixture]
[TestFixture, ExpectPass]
public class TestFixture2
{
[Test]
Expand Down
24 changes: 12 additions & 12 deletions demo/NUnitTestDemo/SimpleTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,75 +7,75 @@ namespace NUnitTestDemo
{
public class SimpleTests
{
[Test]
[Test, ExpectPass]
public void TestSucceeds()
{
Console.WriteLine("Simple test running");
Assert.That(2 + 2, Is.EqualTo(4));
}

[Test]
[Test, ExpectPass]
public void TestSucceeds_Message()
{
Assert.That(2 + 2, Is.EqualTo(4));
Assert.Pass("Simple arithmetic!");
}

[Test]
[Test, ExpectFailure]
public void TestFails()
{
Assert.That(2 + 2, Is.EqualTo(5));
}

[Test]
[Test, ExpectFailure]
public void TestFails_StringEquality()
{
Assert.That("Hello" + "World" + "!", Is.EqualTo("Hello World!"));
}

[Test]
[Test, ExpectInconclusive]
public void TestIsInconclusive()
{
Assert.Inconclusive("Testing");
}

[Test, Ignore("Ignoring this test deliberately")]
[Test, Ignore("Ignoring this test deliberately"), ExpectIgnore]
public void TestIsIgnored_Attribute()
{
}

[Test]
[Test, ExpectIgnore]
public void TestIsIgnored_Assert()
{
Assert.Ignore("Ignoring this test deliberately");
}

[Test]
[Test, ExpectError]
public void TestThrowsException()
{
throw new Exception("Deliberate exception thrown");
}

[Test]
[Test, ExpectPass]
[Property("Priority", "High")]
public void TestWithProperty()
{
}

[Test]
[Test, ExpectPass]
[Property("Priority", "Low")]
[Property("Action", "Ignore")]
public void TestWithTwoProperties()
{
}

[Test]
[Test, ExpectPass]
[Category("Slow")]
public void TestWithCategory()
{
}

[Test]
[Test, ExpectPass]
[Category("Slow")]
[Category("Data")]
public void TestWithTwoCategories()
Expand Down
1 change: 1 addition & 0 deletions demo/NUnitTestDemo/TextOutputTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

namespace NUnitTestDemo
{
[ExpectPass]
public class TextOutputTests
{
[Test]
Expand Down
Loading

0 comments on commit 2782be4

Please sign in to comment.