1

Im using the below structure in testcases for junit4, now im migration to junit5 couldnt find a way to replace, please help.

@RunWith(Karate.class)
@CucumberOptions(
junit = {..},
features = "..",
plugin = {"..."},
glue = {"..."},
tags = {"...."})

Aaccording to junit5 @RunWith should be replace with @Extendwith but when i used @ExtendWith(karate.class) its giving error.

my testclass:

                import KarateTest.utils.WiremockRunner;
            import com.intuit.karate.junit4.Karate;
            import org.junit.jupiter.api.AfterAll;
            import org.junit.jupiter.api.BeforeAll;
            import org.junit.jupiter.api.Disabled;


            @Disabled
            @RunWith(Karate.class)
            @CucumberOptions(
                junit = {".."},
                features = "...",
                plugin = {"..."},
                glue = {"s.."},
                tags = {"..", "...", "..","..."})
            public class HT {

              private static final WiremockRunner wiremock = new WiremockRunner();

              @BeforeAll
              public static void beforeClass() throws Exception {
                wiremock.startWiremock();
                Application.main(new String[] {"--spring.profiles.active=sb-vk"});
              }

              @AfterAll
              public static void tearDown() throws Exception {
                wiremock.stopWiremock();
              }
            }
KVL
  • 95
  • 1
  • 14

1 Answers1

1

There is no such thing as @CucumberOptions any more.

The recommendation is to use the Runner class, where you have full control to set the various options.

Refer to the examples: https://github.com/karatelabs/karate#junit-5-parallel-execution

import com.intuit.karate.Results;
import com.intuit.karate.Runner;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;

class TestParallel {

    @Test
    void testParallel() {
        Results results = Runner.path("classpath:animals").tags("~@skipme").parallel(5);
        assertEquals(0, results.getFailCount(), results.getErrorMessages());
    }

}

For some related information, refer: https://stackoverflow.com/a/65578167/143475

Peter Thomas
  • 54,465
  • 21
  • 84
  • 248
  • 1
    Thank a lot for your quick reply... but already using a wiremock runner in class.. updated the quesion with class. how can i set the options – KVL Oct 31 '22 at 02:47
  • @Learning_machine my first reaction is you should use Karate for mocking, it is much better ;) https://github.com/karatelabs/karate/tree/master/karate-netty - ok, but seriously the design of the `Runner` is that you can use any other annotation or JUnit pattern, because the Karate stuff becomes just plain java. There is no need to use any annotation for running karate tests. Is that clear ? In other words, put the `Runner` in a normal JUnit 5 method annotated with `@Test` and the rest of your test class can do anything else allowed by JUnit. – Peter Thomas Oct 31 '22 at 02:58