mercredi 27 mars 2019

Nested testRunners: Can I runClasses separating tests?

background

I am building a small frame using Cucumber and Junit-quickcheck. Guidelines require writing the scenarios in cucumber and I want to add the possibility of running property based tests. With quicktheories this works fine, but there are some bugs there and it's maintained by a single person so I'd like to switch to junit-quickcheck.

the question

The code works fine but the two tests are now run as one, and in the cucumber report it's not possible to identify them. So what I'd like is to find a way to write the pbt-tests in the PBT class (not as a class for each test!) and then execute them with cucumber as separate tests.

I suppose there should be a way using the TestClass maybe, but I haven't been able to get that working.

Here is my code that runs, but only as described:

public class Steps implements En {
  public Scenario scenario;
}


public Steps() {

  Given("^I exeute a pbt$", () -> {
    System.out.println("Lets run the pbt");
    Result res = JUnitCore.runClasses(PBT.class);
    assertThat(res.getFailures().toString(), res.wasSuccessful(), equalTo(true));
  });

  }
}

and:

@RunWith(JUnitQuickcheck.class)
public class PBT {
  @Property public void concatenationLength(String s1, String s2) {
    assertEquals("nahh", s1.length() + s2.length(), (s1 + s2).length());
  }

  @Property public void reverseTwice(String str){
    assertThat(new StringBuilder(str).reverse().reverse().toString(), equalTo(str));
  }
}

Gives this result:

Running steps.TestRunner
Feature: PBT
Lets run the pbt

  @PBT
  Scenario: First example # PBT.feature:3
    Given I exeute a pbt  # Steps.java:40

1 Scenarios (1 passed)
1 Steps (1 passed)
0m0.597s

Aucun commentaire:

Enregistrer un commentaire