| Deletions are marked like this. | Additions are marked like this. |
| Line 78: | Line 78: |
| * Troy DeMonbreun's [http://blog.troyd.net/PermaLink,guid,21b4cfe8-9d82-443f-86a5-db2d93d6e617.aspx blog] | * Troy !DeMonbreun's [http://blog.troyd.net/PermaLink,guid,21b4cfe8-9d82-443f-86a5-db2d93d6e617.aspx blog] |
I'm currently using NUnit 2.4.4 for these examples. See http://nunit.com/ for documentation, or to download NUnit. (The site http://nunit.org/ tends to lag behind.)
Using the 'Classic' Syntax
using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
namespace NUnitDemo
{
[TestFixture]
public class SimpleTests
{
[Test]
public void TestNada()
{
}
[Test]
public void TestMyClass()
{
MyClass uut = new MyClass();
Assert.AreEqual(25, uut.Square(5));
Assert.AreEqual(36, uut.Square(6));
}
}
}
Using the Constraint-based Syntax
using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
using NUnit.Framework.SyntaxHelpers;
namespace NUnitDemo
{
[TestFixture]
public class ConstraintTests
{
[Test]
public void Nada()
{
}
[Test]
public void StringsWithEqualContentsShouldBeEqual()
{
String aString = "a test string";
Assert.That(aString, Is.EqualTo("a test string"));
}
[Test]
public void StringsWithEqualContentsAreTheSameString()
{
String aString = "a test string";
Assert.That(aString, Is.SameAs("a test string"));
}
[Test]
public void MyClassCanSquareIntegers()
{
MyClass it = new MyClass();
Assert.That(it.Square(5), Is.EqualTo(25));
Assert.That(it.Square(6), Is.EqualTo(36));
}
}
}See also:
Charlie Poole's [http://nunit.com/blogs/?p=44 blog]
Troy DeMonbreun's [http://blog.troyd.net/PermaLink,guid,21b4cfe8-9d82-443f-86a5-db2d93d6e617.aspx blog]
