mirror of
https://gitee.com/dcren/initializr.git
synced 2025-12-26 22:25:51 +08:00
Add @WebAppConfiguration to webapp tests
This commit is contained in:
@@ -79,6 +79,13 @@ class MainController {
|
||||
|
||||
File test = new File(new File(dir, "src/test/java"),request.packageName.replace(".", "/"))
|
||||
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)
|
||||
|
||||
File download = new File(tmpdir, dir.name + ".zip")
|
||||
@@ -97,8 +104,8 @@ class MainController {
|
||||
}
|
||||
|
||||
def write(File src, String name, def model) {
|
||||
def body = template name, model
|
||||
log.info("Creating: " + src + "/" + name)
|
||||
def body = template name, model
|
||||
new File(src, name).write(body)
|
||||
}
|
||||
|
||||
|
||||
@@ -2,13 +2,12 @@ package ${packageName};
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.test.SpringApplicationContextLoader;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
${testImports}import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(classes = Application.class, loader=SpringApplicationContextLoader.class)
|
||||
public class ApplicationTests {
|
||||
@SpringApplicationConfiguration(classes = Application.class)
|
||||
${testAnnotations}public class ApplicationTests {
|
||||
|
||||
@Test
|
||||
public void contextLoads() {
|
||||
|
||||
Reference in New Issue
Block a user