疑问:晚安,
我正在对我的服务进行一些测试,但在 delete 方法中执行测试时遇到问题。
我想知道是否有人遇到过这个错误并且可以帮助我。
当我进行扫描时发生错误。报告的是该方法未使用。
例外:
Wanted but not invoked:
usuariosRepository.findRow(5);
-> at br.com.fortalezaserv.services.impl.tests.RepositoryUsuariosServiceTest.deveExcluirPorId(RepositoryUsuariosServiceTest.java:74)
However, there were other interactions with this mock:
-> at br.com.fortalezaserv.services.impl.RepositoryUsuariosService.excluir(RepositoryUsuariosService.java:74)
at br.com.fortalezaserv.services.impl.tests.RepositoryUsuariosServiceTest.deveExcluirPorId(RepositoryUsuariosServiceTest.java:74)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74)
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:83)
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)
at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
代码:
@ContextConfiguration(classes = TestContext.class)
@RunWith(SpringJUnit4ClassRunner.class)
@TransactionConfiguration(transactionManager = "transactionManager", defaultRollback = true)
public class RepositoryUsuariosServiceTest {
private RepositoryUsuariosService usuarioService;
private UsuariosRepository usuariosRepositoryMock;
private Usuarios usuario;
private Long ID = Long.valueOf(5l);
/**
*
*/
@Before
public void setUp() {
usuario = new Usuarios();
usuario.setEmail("email@me.com");
usuario.setHash("nuadw");
usuario.setLogin("Login");
usuario.setNome("Name");
usuario.setPassword("89331n9183n193n1n9319n3189");
usuarioService = new RepositoryUsuariosService();
usuariosRepositoryMock = mock(UsuariosRepository.class);
usuarioService.setUsuarioRepository(usuariosRepositoryMock);
}
/**
* @throws QualityException
*/
@Test
public void deveExcluirPorId() throws QualityException {
when(usuariosRepositoryMock.findRow(ID)).thenReturn(null);
usuarioService.excluir(ID);
verify(usuariosRepositoryMock, times(1)).findRow(ID);
verify(usuariosRepositoryMock, times(1)).delete(ID);
verifyNoMoreInteractions(usuariosRepositoryMock);
}
}