0

From Program Creek on the net.thucydides example sources I found a solution for altering the name of the test in my JUnit class, but it doesn't work. I still get one test name in my report (as shown in the image link)

Only 1 Test

My ultimate goal is to run the same Maven-Serenity JUnit Test multiple times and report the unique Testname feeded by a parameter coming from the spreadSheetData named "testCase" Maybe my solution doesn't make a change at all, and hopefully it is clear what I want.

Does anyone can help me going forward?

My fragments of code is shown below:

@RunWith(SerenityParameterizedRunner.class)
public class STP_Offer_Flow_Test {
...

public static Collection<Object[]> spreadsheetData() throws IOException {
    InputStream spreadsheet = new FileInputStream("src/test/resources/testdata.xlsx");
    return new SpreadsheetData(spreadsheet, null).getData();

...

public class AnnotatedDataDrivenScenario
{
    private String name;
    @Qualifier
    public String getQualifier()
    {
        return name;
    }
    public String getName()
    {
        return name;
    }
    public void setName(String name)
    {
        this.name = name;
    }
}


@Test
public void STP_Offer_Flow_Basic() throws Throwable {

    log.info(testCase);
    log.info("applicantID = " + applicantID);

    AnnotatedDataDrivenScenario testCaseAnnotation = new AnnotatedDataDrivenScenario();
    testCaseAnnotation.setName(testCase);

...
}
JDelorean
  • 631
  • 13
  • 26

1 Answers1

0

One way to do this is:

@Test
@Title("{0}")
public void myTestMethod(String title){
   ...
}

What this does is put the title into the @Title. It uses title's toString() method so you can pass any object as long as it's toString() method returns anything that would constitute a title (/String).

You can do more, for example:

@Test
@Title("Test Case no. {1} project {0}.")
public void myTest(Project project, int testCaseNo){
   ...
}

Title will state something like this:

Test Case no. 3 project MyProject.


EDIT Scratch all that, this solution only works for Serenity's @Step and not @Title that is used with JUnit's test method. Those need not have any parameters passed to them.

I see only one solution and that is JUnit 5 Dynamic Test. Not sure yet how it will go with Serenity BDD. If you have a chance to test this let me know. I'll edit this answer again if I gain any experience with it too.

JDelorean
  • 631
  • 13
  • 26