You*_*sef 2 java spring cucumber mockito cucumber-java
我正在使用 Cucumber 和 Spring Boot 进行测试
@CucumberContextConfiguration
@ActiveProfiles(profiles = { "cucumber" })
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE)
@ExtendWith(SpringExtension.class)
public class FooTest {
@Autowired
BatchService batchService;
@MockBean
S3ClientService s3ClientService;
@MockBean
HttpClientService httpClientService;
@SpyBean
UndueService undueService;
@Given("^foo cucumber test$")
public void foo_cucumber_test() {
System.out.println("Foo Test");
}
}
Run Code Online (Sandbox Code Playgroud)
当我在 @Given 方法上使用断点运行/调试测试时
我得到了这个奇怪的行为,@Mockbean/@SpyBean被正确注入,但在测试类中它的值是null!我无法运行 Mockito 函数verify或when
但是当我在没有黄瓜的情况下进行测试时
@Test
void fooTest() {
System.out.println("Foo Test");
}
Run Code Online (Sandbox Code Playgroud)
效果很好!这些值不是null
因此,模拟 bean 已创建但未注入到测试套件中。我想你应该同时添加@Autowired和@MockBean注释。
这是一个类似的问题:Spring @MockBean not located with Cucumber
| 归档时间: |
|
| 查看次数: |
4547 次 |
| 最近记录: |