it:ad:unit_testing:automated

IT:AD:Unit Testing:Automated

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.

For server side development, one can use IT:AD:MSTest – although most people find IT:AD:NUnit much more productive.

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.

  • /home/skysigal/public_html/data/pages/it/ad/unit_testing/automated.txt
  • Last modified: 2023/11/04 03:32
  • by 127.0.0.1