mock or stub for chained call

后端 未结 4 1755
不知归路
不知归路 2020-11-29 03:03
protected int parseExpire(CacheContext ctx) throws AttributeDefineException {
    Method targetMethod = ctx.getTargetMethod();
    CacheEnable cacheEnable = targetMe         


        
4条回答
  •  孤城傲影
    2020-11-29 03:46

    I found JMockit easier to use ans switched to it completely. See test cases using it:

    https://github.com/ko5tik/andject/blob/master/src/test/java/de/pribluda/android/andject/ViewInjectionTest.java

    Here I mock away Activity base class, which is coming from Android SKD and completely stubbed. With JMockit you can mock thingis tha are final, private, abstract or whatever else.

    In your testcase it would look like:

    public void testFoo(@Mocked final Method targetMethod, 
                        @Mocked  final CacheContext context,
                        @Mocked final  CacheExpire ce) {
        new Expectations() {
           {
               // specify expected sequence of infocations here
    
               context.getTargetMethod(); returns(method);
           }
        };
    
        // call your method
        assertSomething(objectUndertest.cacheExpire(context))
    

提交回复
热议问题