Cheatography
https://cheatography.com
NUnit example of setup, teardown, and testing
References
Main Site |
|
Nuget Package |
|
Run NUnit Tests in Visual Studio |
|
Arrange Act Assert Pattern |
|
Code Example
using System;
using NUnit.Framework;
namespace NUnitPoc
{
[TestFixture,Category("Optional Category Attribute"), Description("Optional Description")]
public class NUnitPocTests
{
[OneTimeSetUp]
public void OneTimeInitialization()
{
}
[OneTimeTearDown]
public void OneTimeCleanup()
{
}
[SetUp]
public void Initialize()
{
}
[TearDown]
public void Cleanup()
{
}
[Test]
public void ExampleTest()
{
int expected = 1;
int? actual = MethodToTest();
Assert.IsTrue(expected == actual, "expected == actual");
Assert.AreEqual(expected, actual);
Assert.IsFalse(false);
Assert.IsEmpty(string.Empty);
Assert.Throws<NotImplementedException>(NotImplementedMethod);
}
[Test]
public void ParameterizedTest([Values(1, 2, 3)] int value)
{
Console.WriteLine(value);
}
private int MethodToTest()
{
return 1;
}
private void NotImplementedMethod()
{
throw new NotImplementedException();
}
}
}
|
|
Created By
www.kellermansoftware.com
Metadata
Comments
No comments yet. Add yours below!
Add a Comment
Related Cheat Sheets
More Cheat Sheets by GregFinzer