How to organize junit test suites using Allure

3k views Asked by At

So far, beside Junit and Jenkins, I used log4j to textual reporting results of test cases but now I want to use Allure, for generating clearer and more transparent reports from my selenium tests. I'm using maven project where single test case is a java class, and consists of steps which every of them is also a java class. it looks like this:

public class FirstTestCase() {
    new Step1(driver).run();
    new Step2(driver).run();
    new Step3(driver).run();
}

public class SecondTestCase() {
    … second test case steps ...
}

In every step - „run” - contains selenium code.

Individual test cases are grouped into larger sets. For example:

@RunWith(Suite.class)
@Suite.SuiteClasses({
    FirstTestCase.class,
    SecondTestCase.class
})
public class SetOfTests {}

Finally, I have one major class (which is called “TestRunner”) in which the respective sets are activated. It looks like this:

public class TestRunner {
    @Test
    public void main() {
        Result result = JUnitCore.runClasses(
        SetOfTests.class
    );

So, class hierarchy in my project looks like:

TestRunner |-
    SetOfTests |-
        FirstTestCase |-
                        |- Step 1
                        |- Step 2
                        |- ....
        SecondTestCase |-
                        |- Step 1
                        |-Step 2
                        |- ....

Now, my question is: How will be best approach to add Allure annotations (like a @Stories,@Features, @Steps... ) that after the Jenkins “build”, when report will be generated, result will be presented in form as a hierarchy above

Note that, jenkins is configured, works and also generates a report but not in such a form as I want.

Just I need to know in simple way in which test and which step the error occurred

1

There are 1 answers

1
vania-pooh On

If you look at Allure XSD file you will see that currently (1.4.x series) we support the following structure:

TestSuite|
         TestCase|
                  Step|
                      Substep|
                             ...

So test suite can contain a set of test cases (nested test cases are not supported) and each test case can contain a hierarchy of steps with unlimited depth. I would implement a custom JUnit adapter for your case - this is as simple as creating one Java class like the following which implements JUnit RunListener interface.