IT:AD:Unit Testing:Automated
- See also:
Summary
In software testing, test automation is the use of special software (separate from the … Unit tests are written to define the functionality before the code is written.
Process
Framework
For server side development, one can use IT:AD:MSTest – although most people find IT:AD:NUnit much more productive.
Layout
Layout of an automated test usually follows the Arrange-Act-Assert pattern, or the Arrange-Assume-Act-Assert pattern:
[TestFixture]
public class SomeServiceTests {
[Test]
[InitializeIoc]
public void CanGetServiceOfExpectedType(){
//Arrange
var service = XAct.DependencyResolver.Current.GetInstance<ISomeService>();
//Act
//..Do nothing during this test.
//Assert
Assert.IsNotNull(service);
Assert.AreEqual(typeof(SomeService),service.GetType());
}
[Test]
[InitializeIoc]
public void CanGetServiceOfExpectedType(){
//Arrange
var service = XAct.DependencyResolver.Current.GetInstance<ISomeService>();
//Act
var bar = service.Foo();
//Assert
Assert.IsNotNull(bar);
}
}
In the Arrange-Act-Assert pattern, it's not always clear how to wait to the Assert part in order to check things:
[Test]
[InitializeIoc]
public void CanGetServiceOfExpectedType(){
//Arrange
var service = XAct.DependencyResolver.Current.GetInstance<ISomeService>();
Assert.IsNotNull(service);
//Act
var bar = service.Foo();
//Assert
Assert.IsNotNull(bar);
}
}
This is where the Arrange-Assume-Act-Assert pattern can be of use.