Spring mvc junit测试serrice
我正在使用SpringMVC。 我想用Junit测试我的服务。 我想测试是否包含一个新用户 我编写了类测试:Spring mvc junit测试serrice,spring,model-view-controller,testing,junit,Spring,Model View Controller,Testing,Junit,我正在使用SpringMVC。 我想用Junit测试我的服务。 我想测试是否包含一个新用户 我编写了类测试: @ContextConfiguration("/dispatcher-servlet.xml") public class ServizioUtenteTest { @Autowired private ServizioUtente servizioutente; @Test public void testAggiungiUtente() {
@ContextConfiguration("/dispatcher-servlet.xml")
public class ServizioUtenteTest {
@Autowired
private ServizioUtente servizioutente;
@Test
public void testAggiungiUtente() {
//fail("Not yet implemented");
Utente utente=new Docente();
utente.setCognome("Professore");
utente.setPassword("tetxts");
utente.setUsername("xxxx");
servizioutente.aggiungiUtente(utente);
}
@Test
}
当我运行测试时,我得到:
java.lang.NullPointerException
at org.rol.test.ServizioUtenteTest.testAggiungiUtente(ServizioUtenteTest.java:61)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
....)
错误是在线路上抛出的,为什么?
救救我 您缺少
SpringJUnit4ClassRunner
:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("/dispatcher-servlet.xml")
public class ServizioUtenteTest {
//...
另见
@测试注释在做什么?