This version is still in development and is not considered stable yet. For the latest stable version, please use Spring Shell 3.4.0!

Basics

Spring Shell provides a number of utilities and annotations to help when testing your application. Test support is provided by two modules: spring-shell-test contains core items, and spring-shell-test-autoconfigure supports auto-configuration for tests.

To test interactive commands.

@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");
		});
	}
}

To test non-interactive 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");
		});
	}
}