trivago / cucable-plugin

Maven plugin that simplifies running Cucumber scenarios in parallel.
Apache License 2.0
115 stars 47 forks source link

Class name TestNgCucumberRunner Being renamed when Runner are autogenerated #109

Closed VinnieM closed 5 years ago

VinnieM commented 5 years ago

Describe the bug Inside my Runner class I have created an instance of the class TestNGCucumberRunner, this is being replaced by the generated class name.

Firstly let me say that I am not sure if this plugin is supposed to be used with TestNg.

My Runner class looks like this..

//  previous imports deleted
import cucumber.api.testng.TestNGCucumberRunner;

@RunWith(Cucumber.class)
@CucumberOptions(
    features = "target/parallel/features/[CUCABLE:FEATURE].feature",
    glue = {
        "classpath:com.td.web.stepdefs",
        "classpath:com.td.listener"
    },
    plugin = {
        "json:target/cucumber-report/[CUCABLE:RUNNER].json",
    }
)
public class Runner extends AbstractTestNGCucumberTests {

  private TestNGCucumberRunner testNGCucumberRunner;

  /**
   * Functions with @BeforeClass tags will run before the first test method in the current class is
   * invoked.
   */
  @BeforeClass(
      alwaysRun = true
  )
  public void setUpClass() {
    this.testNGCucumberRunner = new TestNGCucumberRunner(this.getClass());
  }

After the automatic code generation this is the code I get

//  previous imports deleted
import cucumber.api.testng.TestNGCucumberLogin_scenario001_run001_IT;

@RunWith(Cucumber.class)
@CucumberOptions(
    features = "target/parallel/features/Login_scenario001_run001_IT.feature",
    glue = {
        "classpath:com.td.web.stepdefs",
        "classpath:com.td.listener"
    },
    plugin = {
        "json:target/cucumber-report/Login_scenario001_run001_IT.json",
    }
)
public class Login_scenario001_run001_IT extends AbstractTestNGCucumberTests {

  private TestNGCucumberLogin_scenario001_run001_IT testNGCucumberLogin_scenario001_run001_IT;

  /**
   * Functions with @BeforeClass tags will run before the first test method in the current class is
   * invoked.
   */
  @BeforeClass(
      alwaysRun = true
  )
  public void setUpClass() {
    this.testNGCucumberLogin_scenario001_run001_IT = new TestNGCucumberLogin_scenario001_run001_IT(this.getClass());
  }

PS: I might be wrong, but is it searching for the word Runner and then replacing them with the class name?

bischoffdev commented 5 years ago

It is correct that the class name is being renamed as there can be multiple runners that each need to have a distinct class name. This is also stated in the documentation (https://github.com/trivago/cucable-plugin#using-a-java-file-as-a-runner-template):

--

If you use a java file (e.g. src/test/java/some/template/CucableJavaTemplate.java), the [CUCABLE:FEATURE] placeholder as well as the class name will be substituted for the generated feature file name(s). The [CUCABLE:RUNNER] placeholder will be replaced by the runner class name.

--

Can you describe what the bug is in your case? Because for me it looks like it is working as expected.

VinnieM commented 5 years ago

I guess the problem was that my Class name was called Runner and inside that I was using the instance of the class TestNgCucumberRunner. While replacing the class name (Runner), and since I was using TestNgCucumberRunner I guess the replacing went haywire.

When I change the name of the my Class from Runner to something else, it seems to be working as expected.