在测试方法上使用@Property似乎没有效果。
这是我的application.yml
greeting: Hello
Run Code Online (Sandbox Code Playgroud)
Application.java
@Controller
public class Application {
@Property(name = "greeting")
String greeting;
@Get
String hello() {
return greeting + " World!";
}
public static void main(String[] args) {
Micronaut.run(Application.class, args);
}
}
Run Code Online (Sandbox Code Playgroud)
现在test1按预期通过,但test2失败了。
@MicronautTest//(rebuildContext = true)
public class DemoTest {
@Inject
@Client("/")
HttpClient client;
@Test
void test1() {
assertEquals(
"Hello World!",
client.toBlocking().retrieve(GET("/"))
);
}
@Property(name = "greeting", value = "Bonjour")
@Test
void test2() {
assertEquals(
"Bonjour World!",
client.toBlocking().retrieve(GET("/"))
);
} …Run Code Online (Sandbox Code Playgroud)