February 3, 2011

A Guide Through the Layers of Automated Testing

 

With automated testing comes many different layers of testing. For new developers this can be a bit overwhelming. Take for example the other day at work when a developer came to me and asked what type of test should they write for a code change they did.

This question got me thinking, with all the different layers of testing out there, how does someone new to automated testing know what tests to create?

So I decided to sit down lay out what the different layers of testing are and when you should use them. This isn’t a complete list, however I feel this is a good base for a new developer to get started in automated testing.

Test Types

  • Unit test – Testing an individual method’s logic, by removing all outside dependencies. You would use frameworks like NUnit and VS Unit Testing Framework to accomplish this.
  • Integration Test – Testing two or more methods together, testing the dependencies between the methods. You would use frameworks like NUnit and VS Unit Testing Framework to accomplish this.
  • Functional Test – Testing a scenario end-to-end from the presenter to the database and back again. This type of test tests the entire application just below the GUI. You would use frameworks like Cucumber and MSpec to accomplish this.
  • GUI Test – Testing the user interface of a form. GUI test should just test the GUI, not the underlying business logic. You would use frameworks like Selenium and Coded UI Tests to accomplish this.

When to Use

Here are some scenarios you may encounter and what tests you would use.

Method Change in Service Data Access Layer

  • Unit Test - need to be written against the method
  • Integration Test (Optional) – written to verify that the data coming back from the database is valid

Method Change in Data Access Layer

  • Unit Test – need to be written against the method
  • Integration Test – written from the data access layer to the service layer and below

Method Change in a Presenter (MVP model)

  • Unit Test – need to be written against the method.
  • Integration Test – written from the method to the data access layer and below.
  • Functional Test (Optional) - If the method is in a presenter, then a cucumber test will need to be written that will do an end to end test from the method.

Change to a Form (Strictly a UI change)

  • GUI Test – against the change.

Conclusion

Deciding to begin testing you code is a very rewarding experience. It can also be a very overwhelming experience. Armed with this information I wish you well on your wonderful journey into automated testing.

2 comments:

  1. If you're new to testing, the attitudes are as important as the nuts and bolts of testing.

    When you make code changes or add code ask yourself, "How do I prove that this works as expected?" and "How do I prove that this didn't break anything else?"

    Testing also saves time over the life of a project. It's worth it.

    ReplyDelete
  2. Excellent sharing Thanks for share i am sure its must help me. thanks for doing this.

    Scrum Process

    ReplyDelete