Cheatography
https://cheatography.com
Example Testusing Microsoft.VisualStudio.TestTools.UnitTesting;
using ValidationLogic;
namespace UnitTests
{
//Class Decorator
[TestClass]
public class EmailValidationTests
{
private EmailValidationLogic _validationLogic;
//Optional, rarely used. Executes before all tests in the assembly are run
[AssemblyInitialize]
public static void AssemblyInit(TestContext context)
{
}
//Optional, rarely used. Runs once before all the tests in this class run
[ClassInitialize]
public static void TestFixtureSetup(TestContext context)
{
}
//This code runs before each test
[TestInitialize]
public void Setup()
{
_validationLogic = new EmailValidationLogic();
}
//Optional, rarely used. Runs once after all tests in the assembly are run
[AssemblyCleanup()]
public static void AssemblyCleanup()
{
}
//Optional, rarely used. This runs once after all the tests in this class are run
[ClassCleanup]
public static void TestFixtureTearDown()
{
}
//This is code runs after each test
[TestCleanup]
public void TearDown()
{
}
//Example Test Method
[TestMethod]
public void EmailShouldNotHaveMoreThanOneAtSymbol()
{
//Arrange
bool expected = false;
//Act
bool result = _validationLogic.IsEmailValid("jsmith@@hotmail.com");
//Assert
Assert.AreEqual(expected, result, "Email should not have more than one @");
}
//Test Exception Being Thrown
[TestMethod]
[ExpectedException(typeof(System.DivideByZeroException))]
public void DivideMethodTest()
{
int x = 1;
int y = x/0;
}
}
}
|
|
Help Us Go Positive!
We offset our carbon usage with Ecologi. Click the link below to help us!
Created By
www.kellermansoftware.com
Metadata
Comments
No comments yet. Add yours below!
Add a Comment
Related Cheat Sheets
More Cheat Sheets by GregFinzer