How to write Test Runner class?

Test Runner class

Test runner class is the starting point in BDD from where the script get executed with the help of junit annotation. Test runner class use junit class annotation which is @Runwith(). This gets execution once we execute the script. There is one another annotation with the name @cucumberOptions. This is use to do some configuration before running the script.

Some options are given below.

a) features:- This option is used to provide the feature file path.

b) glue:- This option is used to provide the step definition file path.

c) tags:- This option is used to provide the tag name in feature file. With the help of this it will execute only those scripts which will match to these tags. In general, we may have many scenarios such as regression, functional or sanity scenario in feature file. This can be executed separately by using tag name.

We can use “and “, “or “,”not” operator while writing tag name. Example given below.

tags= "not @test" # This will run scenario other than tag name @test from feature file.

tags= "@test and @test1" #This will run the scenario which have both the tag name “@test” and “@test1” from feature file.

tags= "@test or @test1" # This will run all the scenario which has tag name “@test” or “@test1” in feature file. See below example.

        //tags= "not @test",
		//tags= "@test and @test1"
		//tags= "@test1 or @test"
        
d) Monochrome:- This option is to print the output on console in readable format. The value should be set to true for this. This can have true or false value.

e) Strict:- This option is used to check if any method is missing in step definition file. And if any step is not defined then it will stop the execution of program. This can have true or false value.

f) dryRun:- This option is used to check if all the steps are defined in step definition file or not. The value of this option should be set as true to check if all the steps are defined in step definition or not. Once it is verified that all the steps are defined then the value can be set as false.

g) Plugin/Format: - This option is use to specify different formatting options to show output report. The reports are generally created in HTML format or Json format. See below example.

For HTML format
plugin= {"pretty","html:target/cucumber-reports/index.html"},

For json formate
plugin= {"pretty","json:target/cucumber-reports/Cucumber.json"}

Runner class

import org.junit.runner.RunWith; import io.cucumber.junit.Cucumber; import io.cucumber.junit.CucumberOptions; @RunWith(Cucumber.class) @CucumberOptions( features = {"src/test/java/org/cuck"}, glue = {"org.Teststep"} , //plugin= {"pretty","html:target/cucumber-reports/index.html"} plugin= {"pretty","json:target/cucumber-reports/Cucumber.json"} , tags= "not @test", //tags= "@test and @test1" //tags= "@test1 or @test" dryRun = true, monochrome = true ) public class RunnerTest { }

Cucumber runner class maven dependency

    <dependency>
            <groupId>io.cucumber </groupId>
            <artifactId>cucumber-java </artifactId>
            <version>6.10.4 </version>
            <scope>test </scope>
     </dependency>

      <dependency>
            <groupId>io.cucumber </groupId>
            <artifactId>cucumber-junit </artifactId>
            <version>6.10.4 </version>
             <scope>test </scope>
      </dependency>

     <dependency>
            <groupId>junit </groupId>
            <artifactId>junit </artifactId>
            <version>4.13.2 </version>
             <scope>test </scope>
     </dependency>
        
Some related topics :-










No comments:

Post a Comment