涉及非模拟类与模拟抽象父类的验证

时间:2017-08-08 16:55:42

标签: jmockit

我的团队成员编写了一个基于JMockit的测试方法,该方法使用Verifications实例来断言在UUT上调用的方法,该方法没有被模拟,但扩展了一个模拟的抽象父级(它恰好是一个Hibernate存储库)。测试通过,但我的观点,基于JMockit文档,只有模拟应该在Verifications实例初始化程序中使用。我认为结果是假阴性但我的团队成员坚持认为这是一个有效的验证电话。测试本身很简单,所以我使用人为的对象重新创建它:

package com.acme.dataacess;

public abstract class AbstractRepository {

    public final T list(Class<T> clazz, final Collection<String> keys) {
       .....
    }
}

package com.acme.module.dataacess

public class FooRepository extends AbstractRepository<Foo> {

    public List<Foo> list() {
        return getFoos(null);
    }

    public List<Foo> list(Collection<String> keys) {
        return list(Foo.class, keys);
   }
}

public class FooRepositoryTest {

    @Tested
    private FooRepository uut;

    @Mocked
    private AbstractRepository mockAbstractRepository;

    @Test
    public void testFoo1() {

       // Execute the test.
       this.uut.list(null);

       // Verify the results.
       new Verifications() {
           {
               // I don't think this is a valid verification, because the goal
               // of the test is to assert a delegated method in a non-mocked
               // class was invoked.
               uut.list(null);
           }
       };

    }
}

这是一个有效的JMockit验证吗?

0 个答案:

没有答案