Unit Testing for test automation

In order to create automated tests for an application, a tester should have decent knowledge of a few things:

- a programming language (Java, Ruby, C#)

- knowledge of the test automation API (let's say WebDriver)

- application/browser DOM 

- XPATH

- unit testing framework (NUNIT, JUNIT)


Some questions that can come up while creating the test automation scripts are related to unit testing:

- What should be tested?

- How should the testing be done?

- How many assertions should be included in a test script?

- How much test code should be written?

- When should the test code be executed?

- What are the characteristics of a good unit test?


For answers for these questions and much more, I recommend the following book:

Pragmatic Unit Testing in C# with NUNIT
by Andrew Hunt, David Thomas


It is a very good presentation of unit testing with NUNIT and C#.

All book's concepts apply as well to other unit testing frameworks and languages, like JUNIT and Java.

This is a checklist extracted from the book with unit testing practices:


General Principles

1. test anything that might break
2. test everything that does break
3. new code is guilty until proven innocent
4. write at least as much test code as production code
5. run local tests with each compile
6. run all tests before check-in to repository


What to test: use your RIGHT-BICEP

1. are the results RIGHT?
2. are all the Boundary conditions CORRECT?
3. can you check Inverse relationships?
4. can you Cross-Check results using other means?
5. can you force Error conditions to happen?
6. are Performance characteristics within bounds?


Questions To Ask:

1. if the code ran correctly, how would I know?
2. how am I going to test this?
3. what else can go wrong?
4. could this type of problem happen anywhere else?


Good tests are A TRIP

Automatic
Thorough
Repeatable
Independent
Professional


CORRECT Boundary Conditions

Conformance - does the value conform to an expected format?

Ordering - is the set of values ordered or unordered as appropriate?

Range - is the value within reasonable minimum and maximum values?

Reference - does the code reference anything external that isn't under direct control of the code itself?

Existence - does the value exist? (e.g., is non-null, non-zero, present in a set, etc)

Cardinality - are there exactly enough values?

Time (absolute and relative) - is everything happening in order? at the right time? in time?

Share this