using MbUnit.Framework;
using System;
namespace AssertDocTests
{
[TestFixture]
public class Asserts
{
// This test succeeds
[Test]
public void IsTrue_True()
{
Assert.IsTrue(true, "This test failed at {0}", DateTime.Now.ToShortDateString());
}
//This test fails
[Test]
public void IsTrue_False()
{
Assert.IsTrue(false, "This test failed at {0}", DateTime.Now.ToShortDateString());
}
}
}
using MbUnit.Framework;
namespace AssertDocTests
{
[TestFixture]
public class Asserts
{
// This test succeeds
[Test]
public void IsTrue_True()
{
Assert.IsTrue(true, "This test failed. Please get it working");
}
//This test fails
[Test]
public void IsTrue_False()
{
Assert.IsTrue(false, "This test failed. Please get it working");
}
}
}
using MbUnit.Framework;
namespace AssertDocTests
{
[TestFixture]
public class Asserts
{
// This test succeeds
[Test]
public void IsTrue_True()
{
Assert.IsTrue(true);
}
//This test fails
[Test]
public void IsTrue_False()
{
Assert.IsTrue(false);
}
}
}
using System;
using MbUnit.Framework;
namespace AssertDocTests
{
[TestFixture]
public class Asserts
{
// This test succeeds
[Test]
public void IsFalse_False()
{
Assert.IsFalse(false, "This test failed at {0}", DateTime.Now.ToShortDateString());
}
//This test fails
[Test]
public void IsFalse_True()
{
Assert.IsFalse(true, "This test failed at {0}", DateTime.Now.ToShortDateString());
}
}
}
using MbUnit.Framework;
namespace AssertDocTests
{
[TestFixture]
public class Asserts
{
// This test succeeds
[Test]
public void IsFalse_False()
{
Assert.IsFalse(false, "This test failed. Please get it working");
}
//This test fails
[Test]
public void IsFalse_True()
{
Assert.IsFalse(true, "This test failed. Please get it working");
}
}
}
using MbUnit.Framework;
namespace AssertDocTests
{
[TestFixture]
public class Asserts
{
// This test succeeds
[Test]
public void IsFalse_False()
{
Assert.IsFalse(true);
}
//This test fails
[Test]
public void IsFalse_True()
{
Assert.IsFalse(false);
}
}
}
using MbUnit.Framework;
namespace AssertDocTests
{
[TestFixture]
public class AreEqualTests
{
// This test passes
[Test]
public void AreEqual_SameValues()
{
Assert.AreEqual(1.0d, 1.0d, 0.0d, "These values are not equal");
}
//This test passes
[Test]
public void AreEqual_ValuesWithinDelta()
{
Assert.AreEqual(1.0d, 1.1d, 0.2d, "These values are not equal");
}
//This test fails with a NotEqualAssertionException
[Test]
public void AreEqual_ValuesNotWithinDelta()
{
Assert.AreEqual(1.0d, 2.0d, 0.2d, "These values are not equal");
}
//This test fails with a NotEqualAssertionException
[Test]
public void AreEqual_OneValueIsInfinity()
{
Assert.AreEqual(double.PositiveInfinity, double.MaxValue, 1.0d, "These values are not equal");
}
//This test passes
[Test]
public void AreEqual_BothValuesSameInfinity()
{
Assert.AreEqual(double.PositiveInfinity, double.PositiveInfinity, 1.0d, "These values are not equal");
}
//This test fails with a NotEqualAssertionException
[Test]
public void AreEqual_DifferentValuesOfInfinity()
{
Assert.AreEqual(double.PositiveInfinity, double.NegativeInfinity, 0.0d, "These values are not equal");
}
//This test fails with a ArgumentException
[Test]
public void AreEqual_NegativeDelta()
{
Assert.AreEqual(1.0d, 1.0d, -0.1d, "These values are not equal");
}
}
}
using MbUnit.Framework;
namespace AssertDocTests
{
[TestFixture]
public class AreEqualTests
{
// This test passes
[Test]
public void AreEqual_SameValues()
{
Assert.AreEqual(1.0d, 1.0d, 0.0d);
}
//This test passes
[Test]
public void AreEqual_ValuesWithinDelta()
{
Assert.AreEqual(1.0d, 1.1d, 0.2d);
}
//This test fails with a NotEqualAssertionException
[Test]
public void AreEqual_ValuesNotWithinDelta()
{
Assert.AreEqual(1.0d, 2.0d, 0.2d);
}
//This test fails with a NotEqualAssertionException
[Test]
public void AreEqual_OneValueIsInfinity()
{
Assert.AreEqual(double.PositiveInfinity, double.MaxValue, 1.0d);
}
//This test passes
[Test]
public void AreEqual_BothValuesSameInfinity()
{
Assert.AreEqual(double.PositiveInfinity, double.PositiveInfinity, 1.0d);
}
//This test fails with a NotEqualAssertionException
[Test]
public void AreEqual_DifferentValuesOfInfinity()
{
Assert.AreEqual(double.PositiveInfinity, double.NegativeInfinity, 0.0d);
}
//This test fails with an ArgumentException
[Test]
public void AreEqual_NegativeDelta()
{
Assert.AreEqual(1.0d, 1.0d, -0.1d);
}
}
}
using MbUnit.Framework;
namespace AssertDocTests
{
[TestFixture]
public class AreEqualTests
{
// This test passes
[Test]
public void AreEqual_SameValues()
{
Assert.AreEqual(1.0d, 1.0d, 0.0d, "Test failed at {0}", DateTime.Now.ToString());
}
//This test passes
[Test]
public void AreEqual_ValuesWithinDelta()
{
Assert.AreEqual(1.0d, 1.1d, 0.2d, "Test failed at {0}", DateTime.Now.ToString());
}
//This test fails with a NotEqualAssertionException
[Test]
public void AreEqual_ValuesNotWithinDelta()
{
Assert.AreEqual(1.0d, 2.0d, 0.2d, "Test failed at {0}", DateTime.Now.ToString());
}
//This test fails with a NotEqualAssertionException
[Test]
public void AreEqual_OneValueIsInfinity()
{
Assert.AreEqual(double.PositiveInfinity, double.MaxValue, 1.0d, "Test failed at {0}", DateTime.Now.ToString());
}
//This test passes
[Test]
public void AreEqual_BothValuesSameInfinity()
{
Assert.AreEqual(double.PositiveInfinity, double.PositiveInfinity, 1.0d, "Test failed at {0}", DateTime.Now.ToString());
}
//This test fails with a NotEqualAssertionException
[Test]
public void AreEqual_DifferentValuesOfInfinity()
{
Assert.AreEqual(double.PositiveInfinity, double.NegativeInfinity, 0.0d, "Test failed at {0}", DateTime.Now.ToString());
}
//This test fails with an ArgumentException
[Test]
public void AreEqual_NegativeDelta()
{
Assert.AreEqual(1.0d, 1.0d, -0.1d, "Test failed at {0}", DateTime.Now.ToString());
}
}
}
using MbUnit.Framework;
namespace AssertDocTests
{
[TestFixture]
public class AreEqualTests
{
// This test passes
[Test]
public void AreEqual_SameValues()
{
Assert.AreEqual(1.0f, 1.0f, 0.0f, "Test failed at {0}", DateTime.Now.ToString());
}
//This test passes
[Test]
public void AreEqual_ValuesWithinDelta()
{
Assert.AreEqual(1.0f, 1.1f, 0.2f, "Test failed at {0}", DateTime.Now.ToString());
}
//This test fails with a NotEqualAssertionException
[Test]
public void AreEqual_ValuesNotWithinDelta()
{
Assert.AreEqual(1.0f, 2.0f, 0.2f, "Test failed at {0}", DateTime.Now.ToString());
}
//This test fails with a NotEqualAssertionException
[Test]
public void AreEqual_OneValueIsInfinity()
{
Assert.AreEqual(float.PositiveInfinity, float.MaxValue, 1.0d, "Test failed at {0}", DateTime.Now.ToString());
}
//This test passes
[Test]
public void AreEqual_BothValuesSameInfinity()
{
Assert.AreEqual(float.PositiveInfinity, float.PositiveInfinity, 1.0d, "Test failed at {0}", DateTime.Now.ToString());
}
//This test fails with a NotEqualAssertionException
[Test]
public void AreEqual_DifferentValuesOfInfinity()
{
Assert.AreEqual(float.PositiveInfinity, float.NegativeInfinity, 0.0d, "Test failed at {0}", DateTime.Now.ToString());
}
//This test fails with a ArgumentException
[Test]
public void AreEqual_NegativeDelta()
{
Assert.AreEqual(1.0f, 1.0f, -0.1f, "Test failed at {0}", DateTime.Now.ToString());
}
}
}
using MbUnit.Framework;
namespace AssertDocTests
{
[TestFixture]
public class AreEqualTests
{
// This test passes
[Test]
public void AreEqual_SameValues()
{
Assert.AreEqual(1.0f, 1.0f, 0.0f);
}
//This test passes
[Test]
public void AreEqual_ValuesWithinDelta()
{
Assert.AreEqual(1.0f, 1.1f, 0.2f);
}
//This test fails with a NotEqualAssertionException
[Test]
public void AreEqual_ValuesNotWithinDelta()
{
Assert.AreEqual(1.0f, 2.0f, 0.2f);
}
//This test fails with a NotEqualAssertionException
[Test]
public void AreEqual_OneValueIsInfinity()
{
Assert.AreEqual(float.PositiveInfinity, float.MaxValue, 1.0d);
}
//This test passes
[Test]
public void AreEqual_BothValuesSameInfinity()
{
Assert.AreEqual(float.PositiveInfinity, float.PositiveInfinity, 1.0d);
}
//This test fails with a NotEqualAssertionException
[Test]
public void AreEqual_DifferentValuesOfInfinity()
{
Assert.AreEqual(float.PositiveInfinity, float.NegativeInfinity, 0.0d);
}
//This test fails with a ArgumentException
[Test]
public void AreEqual_NegativeDelta()
{
Assert.AreEqual(1.0f, 1.0f, -0.1f);
}
}
}
null
If the object is not null then an null
If the object is null then an null
If the object is not null then an null
If the object is null then an null
If the object is null then an null
If the object is null then an NaN value.
If the object is not NaN then an NaN value.
If the object is not NaN then an NaN value.
If the object is not NaN then an
{Provider}
[SetUp]
{Fill}
(Order) // internal
[TearDown]
TimeMonitor timer = new TimeMonitor();
timer.Start();
... // execute code
timer.Stop();
Console.WriteLine("Duration: {0}",timer.Duration);
/************************************************************************************
'
' Copyright 2002-2003 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole
' Copyright 2000-2002 Philip A. Craig
'
' This software is provided 'as-is', without any express or implied warranty. In no
' event will the authors be held liable for any damages arising from the use of this
' software.
'
' Permission is granted to anyone to use this software for any purpose, including
' commercial applications, and to alter it and redistribute it freely, subject to the
' following restrictions:
'
' 1. The origin of this software must not be misrepresented; you must not claim that
' you wrote the original software. If you use this software in a product, an
' acknowledgment (see the following) in the product documentation is required.
'
' Portions Copyright 2002-2003 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole
' or Copyright 2000-2002 Philip A. Craig
'
' 2. Altered source versions must be plainly marked as such, and must not be
' misrepresented as being the original software.
'
' 3. This notice may not be removed or altered from any source distribution.
'
'***********************************************************************************/
[TestFixture("Bitmap")]
public GraphicsAndBitmapTest
{
private Bitmap bmp;
[SetUp]
public void SetUp()
{
this.bmp = new Bitmap(300,300);
}
[Test]
public void CreateGraphics()
{
Graphics g = Graphcis.FromImage(this.bmp);
Assert.IsNotNull(g);
Assert.AreEqual(g.Width,this.bmp.Width);
...
}
...
[TearDown]
public void TearDownCanHaveOtherNames()
{
if(this.bmp!=null)
this.bmp.Dispose();
}
}
Test methods annotated with this attribute will have the specified embedded resource extracted.
For example:
[Test]
[ExtractResource("MyAssembly.Test.txt", "Test.txt")]
public void SomeTest()
{
Assert.IsTrue(File.Exists("Test.txt"));
}
It's possible to extract the resource into a stream as well by not specifying a destination file.
[Test]
[ExtractResource("MyAssembly.Test.txt")]
public void SomeOtherTest()
{
Assert.IsNotNull(ExtractResourceAttribute.Stream);
}
{DataProvider}
{CopyToProvider}
[SetUp]
(EnumerationTester)
- GetEnumerator
- Enumerate
- ElementWiseEquality
- Current
- CurrentWithoutMoveNet
- CurrentPastEnd
- Reset
- CollectionChanged
[TearDown]
[SetUp]
{TestSequence}
[TearDown]
[ProcessTestFixture]
public class POSequenceTest
{
...
[TestSequence(1)]
public void POConstructor()
{
po=new PurchaseOrder();
Assert.AreEqual(po.Number,"", "Number not initialized.");
Assert.AreEqual(po.PartCount,0, "PartCount not initialized.");
Assert.AreEqual(po.ChargeCount,0, "ChargeCount not initialized.");
Assert.AreEqual(po.Invoice,null, "Invoice not initialized.");
Assert.AreEqual(po.Vendor,null, "Vendor not initialized.");
}
[TestSequence(2)]
public void VendorConstructor()
{
vendor=new Vendor();
Assert.AreEqual(vendor.Name,"", "Name is not an empty string.");
Assert.AreEqual(vendor.PartCount,0, "PartCount is not zero.");
}
...
[SetUp]
{Test}
[TearDown]
[Test]
public void UnitTest()
{
...
}
The same fixture can hold an arbitrary number of unit test methods.
[TestFixture("Bitmap")]
public GraphicsAndBitmapTest
{
private Bitmap bmp;
[SetUp]
public void SetUp()
{
this.bmp = new Bitmap(300,300);
}
[Test]
public void CreateGraphics()
{
Graphics g = Graphcis.FromImage(this.bmp);
Assert.IsNotNull(g);
Assert.AreEqual(g.Width,this.bmp.Width);
...
}
...
[TearDown]
public void TearDownCanHaveOtherNames()
{
if(this.bmp!=null)
this.bmp.Dispose();
}
}
[TestFixture("Bitmap")]
public GraphicsAndBitmapTest
{
private Bitmap bmp;
[SetUp]
public void SetUp()
{
this.bmp = new Bitmap(300,300);
}
[Test]
public void CreateGraphics()
{
Graphics g = Graphcis.FromImage(this.bmp);
Assert.IsNotNull(g);
Assert.AreEqual(g.Width,this.bmp.Width);
...
}
...
[TearDown]
public void TearDownCanHaveOtherNames()
{
if(this.bmp!=null)
this.bmp.Dispose();
}
}
[TestFixture("Bitmap")]
public GraphicsAndBitmapTest
{
private Bitmap bmp;
[SetUp]
public void SetUp()
{
this.bmp = new Bitmap(300,300);
}
[Test]
public void CreateGraphics()
{
Graphics g = Graphcis.FromImage(this.bmp);
Assert.IsNotNull(g);
Assert.AreEqual(g.Width,this.bmp.Width);
...
}
...
[TearDown]
public void TearDownCanHaveOtherNames()
{
if(this.bmp!=null)
this.bmp.Dispose();
}
}
{Provider}
[SetUp]
{Test}
[TearDown]
[TypeFixture(typeof(IDictionary),"IDictionary interface fixture")]
public void DictionaryTest
{
[Provider(typeof(Hashtable))]
public Hashtable ProvideHashtable()
{
return new Hashtable();
}
[Provider(typeof(SortedList))]
public SortedList ProvideSortedList()
{
return new SortedList();
}
// tests
[Test]
[ExpectedException(typeof(ArgumentException))]
public void AddDuplicate(IDictionary dic) // dic comes from a provider class
{
dic.Add("key",null);
dic.Add("key",null); // boom
}
}
[TypeFixture(typeof(IDictionary),"IDictionary interface fixture")]
public void DictionaryTest
{
[Provider(typeof(Hashtable))]
public Hashtable ProvideHashtable()
{
return new Hashtable();
}
[Provider(typeof(SortedList))]
public SortedList ProvideSortedList()
{
return new SortedList();
}
// tests
[Test]
[ExpectedException(typeof(ArgumentException))]
public void AddDuplicate(IDictionary dic) // dic comes from a provider class
{
dic.Add("key",null);
dic.Add("key",null); // boom
}
}
/*
******************************************************************
Copyright (c) 2001, Jeff Martin, Tim Bacon
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of the xmlunit.sourceforge.net nor the names
of its contributors may be used to endorse or promote products
derived from this software without specific prior written
permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
******************************************************************
*/