我在src/intrgTest/groovy位置对我的spring boot应用程序进行了简单的集成测试,下面是测试 @AutoConfigureMockMvc
@WebMvcTest
class WebControllerTest extends Specification {
@Autowired
private MockMvc mvc
def "when get is performed then the response has status 200 and content is 'Hello world!'"() {
expe
如何在@Profile中加载spring-test组件,而不必将该配置文件显式地作为启动配置文件启动?
@Configuration
@Profile("dev1")
public class MvcInterceptor extends WebMvcConfigurerAdapter {
//adding a custom interceptor
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(ne
我正处于spock和groovy的初级阶段,我正在尝试测试一个简单的spring引导应用程序,并获得
下面是我的java和groovy代码以及异常细节。
Condition not satisfied:
mvc.perform(get('/hello')).andExpect(status().isOk())
| |
| groovy.lang.MissingMethodException: No signature of method: org.spockframework.controllers.TestControllerSpec
我有以下控制器 @RequestMapping("/locations")
@AllArgsConstructor
@RestController
public class LocationController {
private final LocationService locationService;
@PostMapping
public ResponseEntity<LocationDTO> createLocation(@Valid @RequestBody LocationDTO locationDTO) {
我想编写一个测试,在处理请求时评估具有NullPointerException的控制器的响应。
为此,我编写了一个控制器,在处理请求时抛出一个NullPointer。使用MockMVC控制器,我向该控制器发送一个GET请求。
在处理Null指针时抛出该指针的控制器:
@Controller
public class Controller{
@GetMapping(value = "/api/data")
@ResponseBody
public ResponseEntity<Resource> getData() {
我已经设法解决了Spring、aop和模拟测试服务的问题,使用了中详细介绍的方法。这条线已经超过6年了。
有什么新的方法吗?
编辑,从我的具体实现中添加更多细节。
主计长:
@RestController
public class EndpointController {
private EndpointService endpointService;
@Autowired
public EndpointController(EndpointService endpointService) {
this.endpointService = e