mirror of
https://gitee.com/dcren/initializr.git
synced 2026-09-20 14:57:41 +08:00
Add @WebAppConfiguration to webapp tests
This commit is contained in:
+8
-1
@@ -79,6 +79,13 @@ class MainController {
|
|||||||
|
|
||||||
File test = new File(new File(dir, "src/test/java"),request.packageName.replace(".", "/"))
|
File test = new File(new File(dir, "src/test/java"),request.packageName.replace(".", "/"))
|
||||||
test.mkdirs()
|
test.mkdirs()
|
||||||
|
if (model.styles.contains("-web")) {
|
||||||
|
model.testAnnotations = "@WebAppConfiguration\n"
|
||||||
|
model.testImports = "import org.springframework.test.context.web.WebAppConfiguration;\n"
|
||||||
|
} else {
|
||||||
|
model.testAnnotations = ""
|
||||||
|
model.testImports = ""
|
||||||
|
}
|
||||||
write(test, "ApplicationTests.java", model)
|
write(test, "ApplicationTests.java", model)
|
||||||
|
|
||||||
File download = new File(tmpdir, dir.name + ".zip")
|
File download = new File(tmpdir, dir.name + ".zip")
|
||||||
@@ -97,8 +104,8 @@ class MainController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
def write(File src, String name, def model) {
|
def write(File src, String name, def model) {
|
||||||
def body = template name, model
|
|
||||||
log.info("Creating: " + src + "/" + name)
|
log.info("Creating: " + src + "/" + name)
|
||||||
|
def body = template name, model
|
||||||
new File(src, name).write(body)
|
new File(src, name).write(body)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,13 +2,12 @@ package ${packageName};
|
|||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.springframework.boot.test.SpringApplicationContextLoader;
|
${testImports}import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
|
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
@ContextConfiguration(classes = Application.class, loader=SpringApplicationContextLoader.class)
|
@SpringApplicationConfiguration(classes = Application.class)
|
||||||
public class ApplicationTests {
|
${testAnnotations}public class ApplicationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void contextLoads() {
|
public void contextLoads() {
|
||||||
|
|||||||
Reference in New Issue
Block a user