新的弹簧靴。
@RestController("/path1/path2")
public class SomeController
{
@GetMapping("/path3/path4")
public String doSomething()
{
//code goes here
}
}
测试用例看起来像,
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, classes =
xxx.class)
@AutoConfigureMockMvc(secure = false)
public class AuthServiceTestCase
{
@Autowired
private MockMvc mock;
@Test
public void testDoSomething()
{
//Command 1
mock.perform(get("/path1/path2/path3/path4")).andExpect(status().isOK());
//Command 2
mock.perform(get("/path3/path4")).andExpect(status().isOK());
}
}
“java.lang.AssertionError:预期状态:<200>但实际状态:<404>”
但“命令2”如期成功。
RestController Prefix Path+Controller Prefix Path=整个路径。
为了调用一个API,我们必须遵循上面的格式,但是如果遵循同样的格式,为什么Junit会失败呢?
有人能在这里输入点什么吗?