Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Executing Karate Test suite

I am getting ready for a small demo with karate and I have the following git project https://github.com/TheRasanjana/karateTesting. I'm building a Test suite with several features. I have mock-products.feature which I am invoking with my productRunner.java. As I am hoping to integrate this with jenkins in the future I want to execute all of them as a single test suite.

The tests Run successfully when I run each of the runner classes separately. I have a "AllTest.java" runner class outside the features to Run them all as a suite with command "mvn test -Dtest=AllTest". But in that case it won't invoke the mocks. Do I have to invoke the mocks inside AllTests.java as well?

What will be the right way of running all the features as a suite?

like image 620
Niron Rasanjana Perera Avatar asked Aug 10 '26 00:08

Niron Rasanjana Perera


1 Answers

The best way to run mocks in CI is a) use JUnit and b) include the JUnit classes in your test execution. So all you need to do is mvn test and you can stop referring to any specific test-runner class.

Actually if you rename productsRunner to ProductsTest things are likely to start working the way you expect. If you add an @ignore to products.feature (so they are excluded from AllTest and use @KarateOptions(features = "classpath:features/products/products.feature") in ProductsTest you are all set.

The Karate regression tests use the alternative approach where ProductsRunner is explicitly added to the maven-surefire section of the pom.xml.

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>${maven.surefire.version}</version>
                <configuration>
                    <includes>
                        <include>demo/DemoTestParallel.java</include>
                        <include>mock/contract/*Test.java</include>
                        <include>mock/micro/*Runner.java</include>
                        <include>mock/proxy/*Runner.java</include>
                        <include>ssl/*Test.java</include>
                    </includes>
                </configuration>
            </plugin>   

See the example and read the documentation: https://github.com/intuit/karate#command-line

like image 133
Peter Thomas Avatar answered Aug 11 '26 14:08

Peter Thomas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!