0
这里是我的服务类的JUnit Spring MVC的服务方法返回类型为void
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.integration.Message;
import org.springframework.integration.MessagingException;
import org.springframework.integration.channel.DirectChannel;
import org.springframework.integration.core.MessageHandler;
import org.springframework.stereotype.Service;
@Service
public class EmailService implements MessageHandler {
@Autowired
@Qualifier("receiveChannel")
private DirectChannel messageChannel;
private final Log logger = LogFactory
.getLog(EmailService.class);
public void init() {
logger.info("initializing...");
System.out.println("INIT");
messageChannel.subscribe(this);
}
@Override
public void handleMessage(Message<?> message) throws MessagingException {
logger.info("Message: " + message);
}
}
因为我想创建一个JUnit测试案例初始化。怎么写?
这是我试过的。但它不工作
@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration("classpath:webapptest")
@ContextConfiguration(locations = {"classpath:test-applicationcontext.xml"})
public class EmailServiceTest {
@Autowired
private EmailService emailService;
@Test(timeout=600000)
public void testEmailService() throws Exception {
emailService=Mockito.spy(emailService);
Mockito.doNothing().when(emailService).init();
}
}
在控制台它不打印在init()
方法记录器或打印语句。
我在做什么错误?如何编写测试用例?
谢谢。我如何验证? – iCode
我加了上面的。它仍然不打印任何东西 – iCode
@iProgrammer那么,你告诉它什么都不做。印刷会做点什么,不是吗? –