Since NUnit is being made aware of C# 5 new features, here is a sample unit test on async and await.
The current NUnit downlaod may not work so wait for some time before a stable build is announced.
using NUnit.Framework;
using System.Threading.Tasks;
using System.Threading;
namespace Net45.UnitTests.Samples.Jv
{
[TestFixture]
public class AsyncTest
{
int x = 0;
[Test]
public async void testAddition(){
Assert.AreEqual(15, await returnAdditionResult());
}
[Test]
public async void testAdd()
{
Assert.AreEqual(17, await add(9,8));
}
private async Task add(int a, int b)
{
return a + b;
}
private async Task returnAdditionResult()
{
return await add(9, 7);
}
}
}
The current NUnit downlaod may not work so wait for some time before a stable build is announced.
using NUnit.Framework;
using System.Threading.Tasks;
using System.Threading;
namespace Net45.UnitTests.Samples.Jv
{
[TestFixture]
public class AsyncTest
{
int x = 0;
[Test]
public async void testAddition(){
Assert.AreEqual(15, await returnAdditionResult());
}
[Test]
public async void testAdd()
{
Assert.AreEqual(17, await add(9,8));
}
private async Task
{
return a + b;
}
private async Task
{
return await add(9, 7);
}
}
}
No comments:
Post a Comment