首先,我定义了一个类,比如说Robot.
public class Robot {
private Vision vision;
public Object recognizeObject(List<List<Integer>> frames) {
vision = new Vision();
return vision.recognize(frames);
}
}
Class ofRobot有几个依赖项,其中之一是Vision.
public class Vision {
public Object recognize(List<List<Integer>> frames) {
// do magic stuff, but return dummy stuff
return null;
}
}
然后在测试类中,我简单地测试了recognize().
@RunWith(JMockit.class)
public class RobotTest {
@Test
public void recognizeObjectWithMocked(@Mocked final Vision vision) {
List<List<Integer>> frames = new ArrayList<>();
vision.recognize(frames);
new Verifications() {{
vision.recognize((List<List<Integer>>) any);
times = 1;
}};
}
@Test
public void recognizeObjectWithInjectable(@Injectable final Vision vision) {
List<List<Integer>> frames = new ArrayList<>();
vision.recognize(frames);
new Verifications() {{
vision.recognize((List<List<Integer>>) any);
times = 1;
}};
}
@Test
public void recognizeObjectWithCapturing(@Capturing final Vision vision) {
List<List<Integer>> frames = new ArrayList<>();
vision.recognize(frames);
new Verifications() {{
vision.recognize((List<List<Integer>>) any);
times = 1;
}};
}
}
基于这些测试,我认为@Mocked、@Injectable和@Capturing可以互换使用。
那是对的吗?
如果答案是否定的,那么有没有一种情况,只有 //@Mocked是可能的,而不能被其他的?@Injectable@Capturing
莫回无
相关分类