10 Test Execution - biswajitsundara/Karate GitHub Wiki

Junit Runner

Create a JunitRunner file in the same folder where the feature file is and then run the java file, it will execute the feature file.

  • Feature file is under the package src\test\java --> tests.basic
  • Runner file is under the same package src\test\java --> tests.basic
package tests.basic;
import org.junit.runner.RunWith;
import com.intuit.karate.junit4.Karate;

@RunWith(Karate.class)
public class BasicTestRunner {

}

Maven Test

We can execute the test suites or single feature file using maven test.

  • Before executing the command. clean up target folder using the command mvn clean
  • To run the tests use command mvn test
  • In the Runner file, we can mention feature file and tags to filter out
    @KarateOptions(features = "classpath:animals/cats", tags = "~@ignore")

Command Line

  • mvn test -DargLine="-Dkarate.env=qa"
  • mvn test -DargLine="-Dkarate.env=qa" "-Dkarate.options=--tags @Regression"
  • mvn test "-Dkarate.options=--tags ~@ignore classpath:demo/cats/cats.feature" -Dtest=DemoTestParallel

Default Settings

By default the feature files are expected to be at src/test/resources. However if we want to keep it somewhere else then add below code in the POM.xml file. Also please note that the Runner file needs to be under the same folder where feature files are else it won't work.

  • For example feature files are at src/test/java/tests/..
  • The runner file needs to be at src/test/java/tests/KarateTestRunner.java
<build>
	<testResources>
		<testResource>
		    <directory>src/test/java</directory>
			<excludes>
			      <exclude>**/*.java</exclude>
			</excludes>
		 </testResource>
	 </testResources>

	 <plugins>
		<plugin>
			<groupId>org.apache.maven.plugins</groupId>
			<artifactId>maven-surefire-plugin</artifactId>
			<version>3.0.0-M5</version>
			<configuration>
				<includes>
					<include>tests/KarateTestRunner.java</include>
				</includes>
			</configuration>
		</plugin>
	</plugins>
</build>
⚠️ **GitHub.com Fallback** ⚠️