We haven’t been very good at using automated tests in the DotNetNuke project but that will change dramatically this year.  We have established a Community Quality team who will be focusing on “Integration Tests” using the WatiN Framework, and in the “Open Core” development area we will be creating Unit Tests for new development, as well as back-filling Unit Tests for the older areas of the core.

Over the last few weeks I have spent quite a bit of time in both areas – building Unit Tests for the code I am developing as part of the current sprint and helping the Community Quality Team develop a solid foundation for the Integration tests.

As part of our increased focus on testing, I will be blogging on “Automated Testing” topics in a new series I have called “Adventures in Testing”.

In this first article, I will describe the basic pattern of an automated test – the “Arrange, Act, Assert” pattern.

Listing 1 – A Unit Test written using the Arrange, Act, Assert pattern
   1:  public void Reverse_String()
   2:  {
   3:      //Arrange
   4:      string input = "abc";
   5:   
   6:      //Act
   7:      string result = Util.Reverse(input);
   8:   
   9:      //Assert
  10:      Assert.Equals("cba", result);
  11:  }

 

Listing 1 shows a simple Unit Test designed to test whether the Reverse function correctly reverses the string passed to it.

The first line of code (line 4) of the test sets up (or “arranges”) the pre-conditions for the test – in this case we create a variable (input) to hold the string to be tested “abc”.

Next, in line 7, we execute (or act on) the Result function – the target of out test by calling the function, passing the input string as a parameter and storing the reversed string in the result variable.

Finally, in line 10 the test method checks (or asserts) that the value returned was the expected value.

This clearly demonstrates the simple, but elegant Arrange, Act, Assert pattern.


Posted in: Testing  Tags: , , ,

 Search Blog

 Adsense

 Calendar

«  September 2010  »
MoTuWeThFrSaSu
303112345
6789101112
13141516171819
20212223242526
27282930123
45678910
View posts in large calendar

 Tags

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2010 Thoughts from the Wet Coast