此版本仍在开发中,尚未被视为稳定版本。对于最新的稳定版本,请使用 Spring Shell 3.3.3! |
基本
Spring Shell 提供了许多 Utilities 和 Comments,以帮助测试您的应用程序。
测试支持由两个模块提供:包含核心项,并支持测试的自动配置。spring-shell-test
spring-shell-test-autoconfigure
测试交互式命令。
@ShellTest
@DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD)
class InteractiveTestSample {
@Autowired
ShellTestClient client;
@Test
void test() {
InteractiveShellSession session = client
.interactive()
.run();
await().atMost(2, TimeUnit.SECONDS).untilAsserted(() -> {
ShellAssertions.assertThat(session.screen())
.containsText("shell");
});
session.write(session.writeSequence().text("help").carriageReturn().build());
await().atMost(2, TimeUnit.SECONDS).untilAsserted(() -> {
ShellAssertions.assertThat(session.screen())
.containsText("AVAILABLE COMMANDS");
});
}
}
测试非交互式命令。
@ShellTest
@DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD)
class NonInteractiveTestSample {
@Autowired
ShellTestClient client;
@Test
void test() {
NonInteractiveShellSession session = client
.nonInterative("help")
.run();
await().atMost(2, TimeUnit.SECONDS).untilAsserted(() -> {
ShellAssertions.assertThat(session.screen())
.containsText("AVAILABLE COMMANDS");
});
}
}