Skip to content

Commit 790808b

Browse files
committed
Add more test cases
1 parent d5eb67a commit 790808b

11 files changed

Lines changed: 1197 additions & 18 deletions

Jenkinsfile-junit-k8s

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ pipeline {
1313
steps{
1414
script{
1515
container('java'){
16-
sh 'mvn clean package test'
16+
sh 'mvn test -DSERVER_PORT=1234'
17+
//sh 'mvn test -DSERVER_PORT=2345'
1718
}
1819
}
1920
}

pom.xml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,24 @@
1515
<useSystemClassLoader>false</useSystemClassLoader>
1616
</configuration>
1717
</plugin>
18+
<plugin>
19+
<groupId>org.apache.maven.plugins</groupId>
20+
<artifactId>maven-compiler-plugin</artifactId>
21+
<configuration>
22+
<source>7</source>
23+
<target>7</target>
24+
</configuration>
25+
</plugin>
1826
</plugins>
1927
</build>
2028

2129
<dependencies>
30+
<dependency>
31+
<groupId>org.freemarker</groupId>
32+
<artifactId>freemarker</artifactId>
33+
<version>2.3.20</version>
34+
</dependency>
35+
2236
<dependency>
2337
<groupId>junit</groupId>
2438
<artifactId>junit</artifactId>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package hello;
2+
3+
import freemarker.template.Configuration;
4+
import freemarker.template.Template;
5+
6+
import java.io.File;
7+
import java.io.FileOutputStream;
8+
import java.io.OutputStreamWriter;
9+
10+
/**
11+
* Generate test cases by freemarker.
12+
*/
13+
public class GenerateTestCases {
14+
private Configuration config = new Configuration();
15+
16+
public static void main(String[] args) throws Exception {
17+
GenerateTestCases generator = new GenerateTestCases();
18+
19+
generator.generate("UserSystemTest.java");
20+
generator.generate("AccountSystemTest.java");
21+
generator.generate("WithExceptionTest.java");
22+
}
23+
24+
private void generate(final String fileName) throws Exception {
25+
config.setClassForTemplateLoading(GenerateTestCases.class,"/");
26+
27+
try (OutputStreamWriter writer =
28+
new OutputStreamWriter(new FileOutputStream(new File("target", fileName)))){
29+
Template template = config.getTemplate(fileName, "UTF-8");
30+
template.setEncoding("UTF-8");
31+
template.process(null, writer);
32+
}
33+
}
34+
}
35+
36+

src/main/java/hello/Test.java

Lines changed: 0 additions & 4 deletions
This file was deleted.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package test;
2+
3+
import org.junit.Test;
4+
5+
import static org.junit.Assert.assertEquals;
6+
7+
/**
8+
* This class is only for the test purpose.
9+
*/
10+
public class AccountSystemTest {
11+
private final String EXPECT_IP = "0.0.0.0";
12+
private final String SERVER_IP = System.getProperty("SERVER_IP", EXPECT_IP);
13+
14+
<#list 1..62 as i>
15+
@Test
16+
public void name_${i}() {
17+
assertEquals(EXPECT_IP, SERVER_IP);
18+
}
19+
</#list>
20+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package test;
2+
3+
import org.junit.Ignore;
4+
import org.junit.Test;
5+
6+
import static org.junit.Assert.assertEquals;
7+
8+
/**
9+
* This class is only for the test purpose.
10+
*/
11+
public class UserSystemTest {
12+
private final String EXPECT_PORT = "1234";
13+
private final String SERVER_PORT = System.getProperty("SERVER_PORT", EXPECT_PORT);
14+
15+
<#list 1..62 as i>
16+
@Test
17+
public void name_${i}() {
18+
assertEquals(EXPECT_PORT, SERVER_PORT);
19+
}
20+
</#list>
21+
22+
<#list 1..62 as i>
23+
@Test
24+
@Ignore
25+
public void skip_${i}() {}
26+
</#list>
27+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package test;
2+
3+
import org.junit.Test;
4+
5+
/**
6+
* This class is only for the test purpose.
7+
*/
8+
public class WithExceptionTest {
9+
private final String EXPECT_EXCEPTION = "false";
10+
private final String TEST_EXCEPTION = System.getProperty("TEST_EXCEPTION", EXPECT_EXCEPTION);
11+
12+
<#list 1..62 as i>
13+
@Test
14+
public void name_${i}() throws Exception {
15+
if (!TEST_EXCEPTION.equals(EXPECT_EXCEPTION)) {
16+
throw new Exception();
17+
}
18+
}
19+
</#list>
20+
}

src/main/resources/param.properties

Lines changed: 0 additions & 6 deletions
This file was deleted.

0 commit comments

Comments
 (0)