Posts Tagged ‘testing’

Inheritance of class annotations in TestNG

Posted in java, software development, testing on April 5th, 2009 by Joerg – 1 Comment

Recently Oliver Fischer introduced TestNG at the Berlin-Brandenburg JUG. At one point there was an interesting discussion with the audience about class level annotations. Why should they be used? You can annotate a class like this:

@Test
public class Foo 
{
...

Now every public method in this class is considered a test method. Several people in the audience mentioned that they would still prefer to mark the test explicitly. This is just more readable. But if so, what might be a good reason to use class level annotations?

One very nice characteristic of class level annotations is that they can be inherited. Let’s assume you want several classes in a specific testgroup. What you don’t want to do is to annotate each and every test method with @Test(groups = {“MyTestGroup”}). This is simply not DRY. Using inheritance, you can instead create a base-class like this:

@Test(groups = {"MyTestGroup"})
public class BaseClass 
{
...

Now each test class that should be in this group can just extend BaseClass.

public class MyTestClass extends BaseClass 
{
...

Every public method in these classes is a test method and they belong to the group MyTestGroup. You probably still want to add the @Test annotation to each of the methods for readability. The group assignment is still valid.

What other ideas do you have for making use of annotation inheritance in TestNG?

Super simple method to create a boolean decision table

Posted in software development, testing on March 27th, 2009 by Joerg – 3 Comments

Today one of our test engineers, Manfred, presented about systematic identification of test values. One of the topics were decision tables. I was fascinated how easy he created tables with all possible combinations. Here is how:

    1. Write the conditions in seperate rows.
Condition A 
Condition B
Condition C
    1. Now make 2^n columns where n is the number of conditions.
Condition A |   |   |   |   |   |   |   |   |
Condition B |   |   |   |   |   |   |   |   |
Condition C |   |   |   |   |   |   |   |   |
    1. Start at the bottom condition and write alternating Y and N.
Condition A |   |   |   |   |   |   |   |   |
Condition B |   |   |   |   |   |   |   |   |
Condition C | Y | N | Y | N | Y | N | Y | N |
    1. Fill the next row with alternating Y Y N N …
Condition A |   |   |   |   |   |   |   |   |
Condition B | Y | Y | N | N | Y | Y | N | N |
Condition C | Y | N | Y | N | Y | N | Y | N |
    1. Each row you double the number of consecutive Ys and Ns.
Condition A | Y | Y | Y | Y | N | N | N | N |
Condition B | Y | Y | N | N | Y | Y | N | N |
Condition C | Y | N | Y | N | Y | N | Y | N |
    1. Do so until all rows are filled.
    2. Now you can add your decisions to the table.
Condition A | Y | Y | Y | Y | N | N | N | N |
Condition B | Y | Y | N | N | Y | Y | N | N |
Condition C | Y | N | Y | N | Y | N | Y | N |
---------------------------------------------
Decision 1  |   | X | X |   |   |   |   |   |
...

Using this algorithm you can be sure you covered all combinations. It doesn’t matter how many conditions you have and you don’t even have to think 🙂

Thanks Manfred!