【发布时间】:2017-10-26 18:45:52
【问题描述】:
我正在尝试测试我的应用程序,但是当我使用 @MockBean 时,所有函数都返回 false。 这是我的测试
@RunWith(SpringRunner.class)
@SpringBootTest
public class AppParkingApplicationTests {
@MockBean
Vehicle vehicle;
@MockBean
VehicleController vehicleController;
@Test
public void getValidVehicleTest(){
//Arrange
boolean resp=false;
when(vehicle.getTipo()).thenReturn("Carro");
//Act
resp=vehicleController.getValidVehicle(vehicle.getTipo());
//Assert
assertEquals(true, resp);
}
这就是函数
public boolean getValidVehicle(String tipo){
boolean result=false;
if(tipo.equals("Carro") || tipo.equals("Moto")){
result= true;
}
return result;
}
【问题讨论】:
标签: spring-boot junit mocking