Skip to content

Commit 5b5dedd

Browse files
committed
switched karate-demo to junit5 removed legacy code
1 parent 48038a3 commit 5b5dedd

File tree

140 files changed

+327
-2363
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

140 files changed

+327
-2363
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -3937,7 +3937,7 @@ Karate's `callonce` keyword behaves exactly like [`call`](#call) but is guarante
39373937

39383938
This does require you to move 'set-up' into a separate `*.feature` (or JavaScript) file. But this totally makes sense for things not part of the 'main' test flow and which typically need to be re-usable anyway.
39393939

3940-
So when you use the combination of `callonce` in a `Background`, you can indeed get the same effect as using a [`@BeforeClass`](http://junit.sourceforge.net/javadoc/org/junit/BeforeClass.html) annotation, and you can find examples in the [karate-demo](karate-demo), such as this one: [`callonce.feature`](karate-demo/src/test/java/demo/callonce/call-once.feature).
3940+
So when you use the combination of `callonce` in a `Background`, you can indeed get the same effect as using a [`@BeforeAll`](https://junit.org/junit5/docs/5.0.0/api/org/junit/jupiter/api/BeforeAll.html) annotation, and you can find examples in the [karate-demo](karate-demo), such as this one: [`callonce.feature`](karate-demo/src/test/java/demo/callonce/call-once.feature).
39413941

39423942
A `callonce` is ideally used for only "pure" JSON. You may face issues if you attempt to mix in JS functions or Java code. See [`karate.callSingle()`](#karatecallsingle).
39433943

karate-core/src/test/java/com/intuit/karate/fatjar/FeatureServerTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class FeatureServerTest {
1717
static MockServer server;
1818

1919
@BeforeAll
20-
static void beforeClass() {
20+
static void beforeAll() {
2121
server = MockServer
2222
.feature("classpath:com/intuit/karate/fatjar/server.feature")
2323
.pathPrefix("/v1")
@@ -38,7 +38,7 @@ void testClient() {
3838
}
3939

4040
@AfterAll
41-
static void afterClass() {
41+
static void afterAll() {
4242
server.stop();
4343
}
4444

karate-core/src/test/java/com/intuit/karate/fatjar/ProxyServerSslTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class ProxyServerSslTest {
3939
static MockServer server;
4040

4141
@BeforeAll
42-
static void beforeClass() {
42+
static void beforeAll() {
4343
proxy = new ProxyServer(0, null, null);
4444
server = MockServer.feature("classpath:com/intuit/karate/fatjar/server.feature").https(0).build();
4545
int port = server.getPort();
@@ -49,7 +49,7 @@ static void beforeClass() {
4949
}
5050

5151
@AfterAll
52-
static void afterClass() {
52+
static void afterAll() {
5353
server.stop();
5454
proxy.stop();
5555
}

karate-core/src/test/java/com/intuit/karate/fatjar/ProxyServerTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class ProxyServerTest {
3535
static MockServer server;
3636

3737
@BeforeAll
38-
static void beforeClass() {
38+
static void beforeAll() {
3939
proxy = new ProxyServer(0, null, null);
4040
server = MockServer
4141
.feature("classpath:com/intuit/karate/fatjar/server.feature")
@@ -48,7 +48,7 @@ static void beforeClass() {
4848
}
4949

5050
@AfterAll
51-
static void afterClass() {
51+
static void afterAll() {
5252
server.stop();
5353
proxy.stop();
5454
}

karate-demo/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
</dependency>
7676
<dependency>
7777
<groupId>com.intuit.karate</groupId>
78-
<artifactId>karate-junit4</artifactId>
78+
<artifactId>karate-junit5</artifactId>
7979
<version>${project.version}</version>
8080
<scope>test</scope>
8181
</dependency>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package demo;
2+
3+
import com.intuit.karate.Results;
4+
import com.intuit.karate.Runner;
5+
import com.intuit.karate.junit5.Karate;
6+
import static org.junit.jupiter.api.Assertions.assertTrue;
7+
import org.junit.jupiter.api.BeforeAll;
8+
import org.junit.jupiter.api.Test;
9+
10+
/**
11+
*
12+
* @author peter
13+
*/
14+
class DemoRunner {
15+
16+
@BeforeAll
17+
static void beforeAll() {
18+
TestBase.startServer();
19+
}
20+
21+
@Karate.Test
22+
Karate testAbort() {
23+
// skip 'callSingle' in karate-config.js
24+
return Karate.run("classpath:demo/abort").karateEnv("mock");
25+
}
26+
27+
@Test
28+
void testEncodingParallel() {
29+
Results results = Runner.path("classpath:demo/encoding")
30+
.outputCucumberJson(true)
31+
.parallel(5);
32+
DemoTestParallel.generateReport(results.getReportDir());
33+
assertTrue(results.getFailCount() == 0, results.getErrorMessages());
34+
}
35+
36+
}

karate-demo/src/test/java/demo/DemoTestParallel.java

+8-9
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,29 @@
99
import net.masterthought.cucumber.Configuration;
1010
import net.masterthought.cucumber.ReportBuilder;
1111
import org.apache.commons.io.FileUtils;
12-
import static org.junit.Assert.*;
13-
import org.junit.BeforeClass;
14-
import org.junit.Test;
12+
import org.junit.jupiter.api.BeforeAll;
13+
import org.junit.jupiter.api.Test;
14+
import static org.junit.jupiter.api.Assertions.*;
1515

1616
/**
1717
*
1818
* @author pthomas3
1919
*/
20-
// important: do not use @RunWith(Karate.class) !
2120
public class DemoTestParallel {
2221

23-
@BeforeClass
24-
public static void beforeClass() throws Exception {
25-
TestBase.beforeClass();
22+
@BeforeAll
23+
static void beforeAll() {
24+
TestBase.beforeAll();
2625
}
2726

2827
@Test
29-
public void testParallel() {
28+
void testParallel() {
3029
Results results = Runner.path("classpath:demo")
3130
.outputCucumberJson(true)
3231
.karateEnv("demo")
3332
.parallel(5);
3433
generateReport(results.getReportDir());
35-
assertTrue(results.getErrorMessages(), results.getFailCount() == 0);
34+
assertTrue(results.getFailCount() == 0, results.getErrorMessages());
3635
}
3736

3837
public static void generateReport(String karateOutputPath) {

karate-demo/src/test/java/demo/DemoTestSelected.java

+10-11
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,25 @@
44
import com.intuit.karate.Results;
55
import java.util.Arrays;
66
import java.util.List;
7-
import static org.junit.Assert.*;
8-
import org.junit.BeforeClass;
9-
import org.junit.Test;
7+
import org.junit.jupiter.api.BeforeAll;
8+
import org.junit.jupiter.api.Test;
9+
import static org.junit.jupiter.api.Assertions.*;
1010

1111
/**
12-
* an alternative way to run selected paths, tags and even features using the
13-
* java api here you don't need to use the KarateOptions annotation and you can
12+
* an alternative way to run selected paths, tags and even features and you can
1413
* dynamically determine the features that need to be executed
1514
*
1615
* @author pthomas3
1716
*/
18-
public class DemoTestSelected {
17+
class DemoTestSelected {
1918

20-
@BeforeClass
21-
public static void beforeClass() throws Exception {
22-
TestBase.beforeClass();
19+
@BeforeAll
20+
static void beforeAll() {
21+
TestBase.beforeAll();
2322
}
2423

2524
@Test
26-
public void testSelected() {
25+
void testSelected() {
2726
List<String> tags = Arrays.asList("~@skipme");
2827
List<String> features = Arrays.asList("classpath:demo/cats");
2928
String karateOutputPath = "target/surefire-reports";
@@ -32,7 +31,7 @@ public void testSelected() {
3231
.outputCucumberJson(true)
3332
.reportDir(karateOutputPath).parallel(5);
3433
DemoTestParallel.generateReport(karateOutputPath);
35-
assertTrue(results.getErrorMessages(), results.getFailCount() == 0);
34+
assertTrue(results.getFailCount() == 0, results.getErrorMessages());
3635
}
3736

3837
}
+15-14
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,32 @@
11
package demo;
22

3-
import com.intuit.karate.junit4.Karate;
4-
import org.junit.BeforeClass;
5-
import org.junit.runner.RunWith;
3+
import org.junit.jupiter.api.BeforeAll;
64
import test.ServerStart;
75

86
/**
97
*
108
* @author pthomas3
119
*/
12-
@RunWith(Karate.class)
1310
public abstract class TestBase {
14-
15-
private static ServerStart server;
16-
17-
public static int startServer() throws Exception {
11+
12+
static ServerStart server;
13+
14+
public static int startServer() {
1815
if (server == null) { // keep spring boot side alive for all tests including package 'mock'
1916
server = new ServerStart();
20-
server.start(new String[]{"--server.port=0"}, false);
17+
try {
18+
server.start(new String[]{"--server.port=0"}, false);
19+
} catch (Exception e) {
20+
throw new RuntimeException(e);
21+
}
2122
}
2223
System.setProperty("demo.server.port", server.getPort() + "");
23-
return server.getPort();
24+
return server.getPort();
2425
}
25-
26-
@BeforeClass
27-
public static void beforeClass() throws Exception {
26+
27+
@BeforeAll
28+
public static void beforeAll() {
2829
startServer();
2930
}
30-
31+
3132
}

karate-demo/src/test/java/demo/abort/AbortRunner.java

-20
This file was deleted.

karate-demo/src/test/java/demo/binary/BinaryRunner.java

-11
This file was deleted.

karate-demo/src/test/java/demo/callarray/CallJsonArrayRunner.java

-13
This file was deleted.

karate-demo/src/test/java/demo/calldynamic/CallDynamicJsonRunner.java

-13
This file was deleted.

karate-demo/src/test/java/demo/callfeature/CallFeatureRunner.java

-13
This file was deleted.

karate-demo/src/test/java/demo/callnested/CallNestedRunner.java

-13
This file was deleted.

karate-demo/src/test/java/demo/callonce/CallOnceRunner.java

-11
This file was deleted.

karate-demo/src/test/java/demo/callonce/call-once.feature

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Feature: test set-up routines that run only once, similar to how @BeforeClass works
1+
Feature: test set-up routines that run only once, similar to how @BeforeAll works
22

33
Background:
44

karate-demo/src/test/java/demo/calltable/CallTableRunner.java

-13
This file was deleted.

karate-demo/src/test/java/demo/cats/CatsJava.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
package demo.cats;
2525

2626
import com.intuit.karate.demo.domain.Cat;
27-
import org.junit.Test;
28-
import static org.junit.Assert.*;
27+
import org.junit.jupiter.api.Test;
28+
import static org.junit.jupiter.api.Assertions.*;
2929

3030
/**
3131
*

karate-demo/src/test/java/demo/cats/CatsPutRunner.java

-13
This file was deleted.

karate-demo/src/test/java/demo/cats/CatsRunner.java

-13
This file was deleted.

0 commit comments

Comments
 (0)