[ 
https://issues.apache.org/jira/browse/SUREFIRE-1724?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16980548#comment-16980548
 ] 

M.P. Korstanje commented on SUREFIRE-1724:
------------------------------------------

Heya thanks for getting back so quickly. I am going to reply piecemeal. There 
are quite a few points to touch upon.

> AFAIK Cucumber works with classes

It is a common misconception - classes are involved but they are not the test.

 

In simple terms cucumber test consists of two parts: a feature file and glue 
code.

The feature file is a plain text file with the .feature suffix. For example:
 
{code:java}
Feature: Eating too many cucumbers may not be good for you

  Eating too much of anything may not be good for you.

  Scenario: Eating a few is no problem
    Given Alice is hungry 
    When she eats 3 cucumbers
    Then she will be full
     And still hungry{code}

The Given/When/Then lines are called steps and part of a scenario. A scenario 
would be comparable to a single test annotated method in JUnit.

 

To execute a scenario there must be some Java code to make these steps 
executable. For example:


{code:java}
public class StepDefinitions {

    private Person person  


    @Given("Alice is hungry")
    public void aliceIsHungry(){
        person = new Person("Alice")
        person.setHungry(true);
    }
    @When("she eats {int} Cucumbers")
    public void sheEatsCucumbers(int cucumbers){
       person.eat(cucumbers);

    ....

}

{code}

To execute the Given line Cucumber will invoke the method annotated with "Alice 
is hungry". To invoke the When line Cucumber will invoke the method annotated 
with "she eats \{int} Cucumbers", ect. And as you can see the step definition 
classes are not the tests. The feature file is.

> the way how Surefire discovers the classes should be satisfactory

It was with with JUnit4. Cucumber would implement a JUnit4 Runner class.  For 
example:



 
{code:java}
package io.cucumber.example;

import io.cucumber.junit.Cucumber;
import org.junit.runner.RunWith;

@RunWith(Cucumber.class)
public class RunCucumberTest {
}

{code}
 

 

However with the Junit Platform there is no need for this class any more. The 
JUnit Platform implementation of Cucumber will use the ClassPathRoot and other 
discovery selectors to discover feature files in the selected locations.

For now as a work around I'm adding a marker class that will be discovered by 
Surefire. Cucumber will then scan the package of the annotated class for 
features. But this is less then ideal - we have this superfluous class that 
must be present for all the magic to work.



 
{code:java}
@Cucumber
public class RunCucumberTest {
}

{code}




 

 

> Support JUnit Platform DiscoverySelectors 
> ------------------------------------------
>
>                 Key: SUREFIRE-1724
>                 URL: https://issues.apache.org/jira/browse/SUREFIRE-1724
>             Project: Maven Surefire
>          Issue Type: Improvement
>            Reporter: M.P. Korstanje
>            Priority: Major
>
> The JUnit Platform defines multiple 
> [DiscoverySelectors|https://junit.org/junit5/docs/5.0.2/api/org/junit/platform/engine/DiscoverySelector.html]
>  to discover tests in different locations. This allows TestEngines to 
> discover tests in classes, the class path root, resource root, files, ect.
> Currently Surefire supports TestEngine implementations  through the 
> JUnitPlatformProvider. However the JUnitPlatformProvider only issues 
> discovery requests for classes that have already been discovered by Surefire. 
> Additionally if no tests were discovered by Surefire then no test discovery 
> requests will be issued at all.
> This means that Surefire does not fully utilize the discovery capabilities of 
> the JUnit Platform and makes it impossible to use the JUnitPlatformProvider 
> for test frameworks that do not have class based tests such as Cucumber.
> To make Cucumber work at the very least the class path root discovery 
> selector would have to be supported.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to