Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/382.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如果不是直接依赖关系,我可以模拟对测试系统的依赖关系吗?_Java_Junit_Mockito_Spring Test - Fatal编程技术网

Java 如果不是直接依赖关系,我可以模拟对测试系统的依赖关系吗?

Java 如果不是直接依赖关系,我可以模拟对测试系统的依赖关系吗?,java,junit,mockito,spring-test,Java,Junit,Mockito,Spring Test,我的问题涉及Mockito、JUnit和Spring测试 假设我在应用程序中有以下依赖关系图: SystemUnderTest --> Service1 --> Service2 --> ServiceN 我是否可以模拟ServiceN,即使它不是被测系统的直接依赖(SystemUnderTest),而是可传递的依赖(只有Service1是上面的直接依赖) 所有这些,假设Service1和Service2本身没有被模仿(除了spy())之外)。是的,注释是可能的 谢谢您能在

我的问题涉及Mockito、JUnit和Spring测试

假设我在应用程序中有以下依赖关系图:

SystemUnderTest --> Service1 --> Service2 --> ServiceN
我是否可以模拟
ServiceN
,即使它不是被测系统的直接依赖(
SystemUnderTest
),而是可传递的依赖(只有
Service1
是上面的直接依赖)


所有这些,假设
Service1
Service2
本身没有被模仿(除了
spy()
)之外)。是的,注释是可能的


谢谢您能在回复中添加更多细节吗?@balteo添加了一个示例您已经尝试过了吗?发布您为实现这一点所做的一些尝试。。这绝对是可能的Hi Maciej,谢谢你的评论。我还没试过。在实现一个示例之前,我有兴趣获得反馈和一般考虑。
@RunWith(SpringRunner.class)
@SpringBootTest
public class MockBeanIntegrationTest {
    @MockBean
    private SomeService someService;
    @Before
    public void setupMock() {
        when(someService.getResult())
            .thenReturn("success");
    }
}