2016-08-12 78 views
-2

我正在学习使用mockito在junit中编写测试用例。任何人都可以请解释如何使用ArgumentCaptor编写junit测试来获取这种方法吗?使用参数junit测试mockitoCaptor

public int mtd(A a){ 
int value=dao.getValues(a); 
return value; 
} 

我的JUnit测试案例是这样的

@RunWith(MockitoJUnitRunner.class) 
public class SampleTest { 

    @Mock 
    private InternDAO internDAO; 

    @Mock 
    InternServiceImpl service; 

    @Before 
    public void init() { 
    service = new InternServiceImpl(); 
    } 
    @Test 
    public void test() throws DataServiceException, BusinessServiceException { 

     Intern intern=new Intern(); 
    intern.setStartDate(new Date()); 
    intern.setEndDate(new Date()); 
    Mockito.when(service.doSignedUpCount(intern)).thenReturn(2); 
    int val=service.doSignedUpCount(intern); 
Assert.assertEquals(val, 2); 

    } 

} 

它,我抛出空指针异常

+0

请说明你已经试过了吗?如果您不知道从哪里开始,请查看文档:http://stackoverflow.com/documentation/mockito/2055/introduction-to-mockito/16192/verifying-arguments-with-argumentcaptor#t=201608120856397601709 – noscreenname

回答

0

首先感谢@noscreenname帮助我的。 我得到了NullPointerException,因为我没有设置internDAO对象的值。