我想写一个测试用例来检查我的控制器(getPersons).这是服务器端代码.我有什么困惑我应该放在里面@ContextConfiguration(locations={"file:src/main/webapp/WEB-INF/app-contest.xml"})
其次,我遇到了一些错误:
无法加载应用程序上下文.找不到我在@ContextConfiguration中指定的路径[
我有这样的结构:
restAPI
*src/main/java
com.company.controller
personController.java
*Test
com.company.testController
personControllerTest.java
*src
main
webapp
WEBINF
app-context.xml
@Autowired
private PersonService personService;
@RequestMapping(value="/t2/{yy_id}/person", method=RequestMethod.GET)
@ResponseBody
public PersonInfo[] getPersons() {
return personService.getPersons();
}
Run Code Online (Sandbox Code Playgroud)
这是我的测试
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"classpath:WEB-INF/app-context.xml"})
@WebAppConfiguration
public class PersonControllerTest {
@Autowired
private WebApplicationContext wac;
private MockMvc mockMvc;
@Before
public void setup() {
this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build();
}
@Autowired
private PersonService personService;
@Test
public void getPersons() throws Exception {
this.mockMvc.perform(get("/t2/1/person")
.accept(MediaType.APPLICATION_JSON))
.andExpect(status().isOk());
}
Run Code Online (Sandbox Code Playgroud)
跟踪
java.lang.IllegalStateException: Failed to load ApplicationContext
at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:157)
at org.springframework.test.context.web.ServletTestExecutionListener.setUpRequestContextIfNecessary(ServletTestExecutionListener.java:103) …Run Code Online (Sandbox Code Playgroud) 嗨,我是Spring和Junit的新手.我的控制器中有一个方法.我想为这个方法编写Junit(getPersons()).
@Autowired
private PersonService personService;
@RequestMapping(value="/t2/{yy_id}/person", method=RequestMethod.GET)
@ResponseBody
public PersonInfo[] getPersons() {
return personService.getPersons();
}
Run Code Online (Sandbox Code Playgroud)
有人可以帮助我并以正确的方式指导我.请举个例子.
我正在寻找一种录制我的声音的方法 - 根据录制的声音 - 向左或向右移动动画.
我听说HTML5有一个音频API,您可以通过它来录制您的声音,但我不知道如何做到这一点.
我将感谢能够帮助我或提出解决此问题的解决方案,建议,代码或指南的所有人.
我在运行时遇到问题来编译这段代码,这向我抛出了一个错误,即 java.lang.Integer 无法转换为 Java.lang.Double。如果有人帮我更正此代码,我会非常高兴
double x;
public Double getMethod() {
HashMap hashmap= new HashMap();
hashmap = SumCal();
List listabc = (List) hashmap.get("abclist");
int total=(Integer) hashmap.get("all_total");
x = (Double) listabc.get(0)*100/total;
return x;
}
Run Code Online (Sandbox Code Playgroud) junit ×2
junit4 ×2
spring ×2
spring-mvc ×2
arrays ×1
html5 ×1
html5-audio ×1
jakarta-ee ×1
java ×1
junit3 ×1
three.js ×1
tquery ×1