Jukito高效组合测试框架
JUnit、 Guice、 Mockito 高效组合测试框架。
如果你使用 Google Guice,或者如果你的GWT应用程序使用 Gin,那么,Jukito 是解决你的单元测试头痛的灵丹妙药。现在,你可进行如下测试:
@RunWith(JukitoRunner.class) public class EmailSystemTest { @Inject EmailSystemImpl emailSystem; Email dummyEmail; @Before public void setupMocks( IncomingEmails incomingEmails, EmailFactory factory) { dummyEmail = factory.createDummy(); when(incomingEmails.count()).thenReturn(1); when(incomingEmails.get(0)).thenReturn(dummyEmail); } @Test public void shouldFetchEmailWhenStarting( EmailView emailView) { // WHEN emailSystem.start(); // THEN verify(emailView).addEmail(dummyEmail); } }
或者:
@RunWith(JukitoRunner.class) public class CalculatorTest { public static class Module extends JukitoModule { protected void configureTest() { bindMany(Calculator.class, ScientificCalculator.class, BusinessCalculator.class); bindManyInstances(AdditionExample.class, new AdditionExample(1, 1, 2), new AdditionExample(10, 10, 20), new AdditionExample(18, 24, 42)); } } @Test public void testAdd(@All Calculator calculator, @All AdditionExample example) { // WHEN int result = calculator.add(example.a, example.b); // THEN assertEquals(example.expected, result); } }
评论