does serenity parameterised runner allow custom column names?

547 views
Skip to first unread message

Aleksandr Hlapov

unread,
Sep 5, 2017, 1:27:30 PM9/5/17
to Serenity BDD Users Group
Tl;dr;
1. (main question) Is is possible to set custom column names in parametrised test?
2. (just noticed, while was wrinting this post) When some parameter equals to previous parameter scenario outline show first parameter number

1.
junit parametrised runner allow to set custom column names http://junit.org/junit5/docs/current/user-guide/#writing-tests-parameterized-tests-display-names. From net.thucydides.junit.annotations.TestData (currently i'm using serenity version 1.5.4-rc1) it looks like serenity should also provide same functionality. But it looks strange. Tried to find out correct syntax:

@TestData(columnNames = "{Index}: p0_column_name({0}) p1_column_name({1}) p2_column_name({2}) p3_column_name({3})")
public static Collection<Object[]> testData() {

}

@Parameterized.Parameter
private String parameter0;

@Parameterized.Parameter(1)
private String parameter1;

@TestData(columnNames = "{Index}: p0_column_name({0}) p1_column_name({1}) p2_column_name({2}) p3_column_name({3})")
public static Collection<Object[]> testData() {

}

@TestData(columnNames = "p0_column_name p1_column_name p2_column_name p3_column_name")
public static Collection<Object[]> testData() {

}

@TestData(columnNames = "p0_column_name#0 p1_column_name#1 p2_column_name#2 p3_column_name#3")
public static Collection<Object[]> testData() {

}

@TestData(columnNames = "p0_column_name{0} p1_column_name{1} p2_column_name{2} p3_column_name{3}")
public static Collection<Object[]> testData() {

}

Every time command line show that test passed but build fail

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-failsafe-plugin:2.20:verify (default) on project mbp-tests: There are test failures.

[ERROR] Please refer to …\target\failsafe-reports for the individual test results.
[ERROR] Please refer to dump files (if any exist) [date]-jvmRun[N].dump, [date].dumpstream and [date]-jvmRun[N].dumpstream.
[ERROR] org.apache.maven.surefire.booter.SurefireBooterForkException: There was an error in the forked process
[ERROR] Test mechanism :: Index: 1, Size: 1
[ERROR]         at org.apache.maven.plugin.surefire.booterclient.ForkStarter.fork(ForkStarter.java:665)
[ERROR]         at org.apache.maven.plugin.surefire.booterclient.ForkStarter.fork(ForkStarter.java:533)
[ERROR]         at org.apache.maven.plugin.surefire.booterclient.ForkStarter.run(ForkStarter.java:279)
[ERROR]         at org.apache.maven.plugin.surefire.booterclient.ForkStarter.run(ForkStarter.java:243)
[ERROR]         at org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeProvider(AbstractSurefireMojo.java:1077)
[ERROR]         at org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeAfterPreconditionsChecked(AbstractSurefireMojo.java:907)
[ERROR]         at org.apache.maven.plugin.surefire.AbstractSurefireMojo.execute(AbstractSurefireMojo.java:785)
[ERROR]         at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
[ERROR]         at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
[ERROR]         at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:154)
[ERROR]         at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:146)
[ERROR]         at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:117)
[ERROR]         at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:81)
[ERROR]         at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
[ERROR]         at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
[ERROR]         at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:309)
[ERROR]         at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:194)
[ERROR]         at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:107)
[ERROR]         at org.apache.maven.cli.MavenCli.execute(MavenCli.java:993)
[ERROR]         at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:345)
[ERROR]         at org.apache.maven.cli.MavenCli.main(MavenCli.java:191)
[ERROR]         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[ERROR]         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
[ERROR]         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[ERROR]         at java.lang.reflect.Method.invoke(Method.java:498)
[ERROR]         at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
[ERROR]         at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
[ERROR]         at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
[ERROR]         at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)

and report looks broken



when @TestData don't have parameter buld succesful and report show columns

2.
Let's say i have parametrised test with 3 parameters (3 strings):
{aaa, bbb, aaa}
{111, 222, 333}

given that … «parameter1»
when … «parameter2»
then … «parameter3»

in first case parameter1 equals parameter3. Scenario ouline block will show «then … (<Parameter 1>)» instead of «then … (<Parameter 3>)» is it ok?
Auto Generated Inline Image 1

John Smart

unread,
Sep 6, 2017, 2:05:18 AM9/6/17
to Aleksandr Hlapov, Serenity BDD Users Group
You can do something like this:

@TestData(columnNames = "param-A,param-B")

public static Collection<Object[]> testData() {
    return Arrays.asList(new Object[][]{
{"a", 1},
{"b", 2},
{"c", 3}
});
}

Note that Serenity uses Unit 4.12, not JUnit 5, which is a total non-backward-compatible rewrite of JUnit. Refactoring to JUnit 5 will also need a rewrite of much of the Serenity JUnit code base (not necessarily a bad thing), but from what I've seen will force everyone to make non-trivial changes in their test suites.

I've seen point 2 happen at times, but haven't been able to track it down. Any help would be a great place to start getting into contributing to the Serenity code base ;-).


--
You received this message because you are subscribed to the Google Groups "Serenity BDD Users Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to thucydides-users+unsubscribe@googlegroups.com.
To post to this group, send email to thucydides-users@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
___________________________________________________
John Smart | Wakaleo Consulting  |  +44 7398 832273
Making smart teams collaborate better
http://johnfergusonsmart.com  |  john....@wakaleo.com
___________________________________________________

We love breaking down silos and helping smart teams collaborate better! Ask about our tailored on-site workshops in Agile Product Planning, BDD Requirements Discovery,  BDD, TDD and Clean Coding, and Advanced BDD Test Automation.

Need some help with Serenity BDD? Check out our Serenity BDD training and support packages here.
___________________________________________________

Aleksandr Hlapov

unread,
Sep 6, 2017, 1:21:25 PM9/6/17
to Serenity BDD Users Group, oleksand...@gmail.com
thank you for answer. In case with comman got even bigger error. A little bit later, on weekends, will try to investigate and, may be, create some small dummy project (not allowed to share code, not sure why) to reproduce this errors. May be problem some where in environment (my os) so also will try different environments.
To unsubscribe from this group and stop receiving emails from it, send an email to thucydides-use...@googlegroups.com.
To post to this group, send email to thucydid...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Aleksandr Hlapov

unread,
Sep 22, 2017, 10:07:53 AM9/22/17
to Serenity BDD Users Group
ok, looks like stuck and need help. Currently i'm able to reproduce https://github.com/aleksandrHlapov/serenityScenarioOutlineTests problem and know what cause it net.thucydides.core.model.DataTable#restoreVariablesIn
public String restoreVariablesIn(String stepDescription) {
for(int column = 0; column < getHeaders().size(); column++) {
String correspondingValueInFirstRow = getRows().get(0).getStringValues().get(column);
if (StringUtils.isNotEmpty(correspondingValueInFirstRow)) {
stepDescription = stepDescription.replaceAll("\\b" + withEscapedRegExChars(correspondingValueInFirstRow) + "\\b", "{{" + column + "}}");
}
}

int field = 0;
for(String header : getHeaders()) {
stepDescription = StringUtils.replace(stepDescription, "{{" + field + "}}", "<" + header + ">");
field++;
}

return stepDescription;
}

but don't know how to fix. I was thinking about use attribute name from test case as header and field.

John Smart

unread,
Sep 22, 2017, 10:18:54 AM9/22/17
to Aleksandr Hlapov, Serenity BDD Users Group
That is good progress Aleksandr. That method is tested in tests from here on: https://github.com/serenity-bdd/serenity-core/blob/5f063953da9a42d75fb357a09c32958dcf7af9c7/serenity-core/src/test/groovy/net/thucydides/core/model/WhenRecordingDataDrivenTestOutcomes.groovy#L54

A good start would be to add a failing test case to reproduce the issue.

To unsubscribe from this group and stop receiving emails from it, send an email to thucydides-users+unsubscribe@googlegroups.com.
To post to this group, send email to thucydides-users@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages