Cucumber – JUnit Runner | Code Factory


Donate : Link

Medium Blog : Link

Applications : Link

Cucumber Tutorial Index Page: Link

  • JUnit is a opensource unit testing framework for Java programming language.
  • The reason we are discussing about JUnit in Cucumber framework is, one hand, Cucumber is providing a way of non-technical person to define test cases for a product, and on the other hand, our expectation is smooth & timely execution of such test cases.
  • JUnit acts as a bridge b/w these two. So the flow of execution look likes as follows.
    • Stakeholders will write down feature files.
    • Step definition will be created accordingly.
    • Specify JUnitRunner class to run the series of test cases.
    • Once we run the JUnitRunner class.
      • It will parse the Gherkin feature file.
      • It will execute the functions written in step definition file according to feature file statements.
      • JUnit will combine test case result.
      • It will build the test report in the specified format (HTML/Json)
  • To run specific feature file Cucumber uses standard JUnit runner and specify the tags @CucumberOptions.
  • Multiple tags can be given by comma separate.
  • We can specify the path of the report & type of the report we want to generate.
  • Example
@Runwith(cucumber.class)
@CucumberOptions(format={"samplehtmlreport:report/smoketestreport.html"}, tags={@smokeTest})
public class JunitRunner {
    
}

Leave a comment