我的测试电话有问题。我想在Arquillian容器中测试spring项目。这是我的测试课:
@RunWith(Arquillian.class)
@ContextConfiguration(classes = {WebAppConfigTest.class})
@WebAppConfiguration("src/test/webapp")
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class AutoTest {
@Autowired
WebApplicationContext context;
Gson gson = new Gson();
QuestionModel questionModel = new QuestionModel();
List<OptionModel> optionModelList = new ArrayList<>();
OptionModel optionModel1 = new OptionModel();
Long s;
MockMvc mockMvc ;
MvcResult result;
RequestBuilder request;
MvcResult res;
String jsonstr;
@Deployment
public static Archive createTestArchive() {
// Import Maven runtime dependencies
File[] files = Maven.resolver()
.loadPomFromFile("pom.xml")
.importRuntimeDependencies()
.resolve()
.withTransitivity()
.asFile();
Arrays.stream(files).forEach(file -> {
System.out.println("*********************************"+file.getName()+"*********************************");
});
// Create deploy file
WebArchive war = ShrinkWrap.create(WebArchive.class)
.addClasses(AutoTest.class )
.addAsLibraries(files);
// Show the deploy structure
System.out.println(war.toString(true));
return war;
}
@Test
public void FindTest() throws Exception {
mockMvc = MockMvcBuilders.webAppContextSetup(context).build();
request = MockMvcRequestBuilders.get("/question/find/19").accept(MediaType.APPLICATION_JSON);
res = mockMvc.perform(request).andReturn();
}
} }
运行它时,出现此异常:
java.lang.NoClassDefFoundError: org/springframework/test/web/servlet/RequestBuilder
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Class.java:2658)
at java.lang.Class.getConstructors(Class.java:1638)
at org.junit.runners.model.TestClass.<init>(TestClass.java:47)
at org.junit.runners.ParentRunner.createTestClass(ParentRunner.java:88)
at org.junit.runners.ParentRunner.<init>(ParentRunner.java:83)
at org.junit.runners.BlockJUnit4ClassRunner.<init>(BlockJUnit4ClassRunner.java:65)
at org.jboss.arquillian.junit.Arquillian.<init>(Arquillian.java:58)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
at java.lang.Thread.run(Thread.java:744)
Caused by: java.lang.ClassNotFoundException: org.springframework.test.web.servlet.RequestBuilder from [Module "deployment.56b22f8f-a804-46d0-9863-b42cf8a69b9c.war" from Service Module Loader]
我将所有需求依赖项添加到pom文件中,但是出了点问题! 有人可以帮我解决这个异常吗?