Skip to content

Commit a8b05df

Browse files
committed
Redesign test utilities
- Simplify test utilities to be more user focused - Remove unused APIs and dependencies - Remove jediterm fork - Update Spring Boot test client auto-configuration - Update documentation Resolves #1234 Resolves #1225
1 parent e337e34 commit a8b05df

File tree

75 files changed

+233
-9376
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+233
-9376
lines changed

spring-shell-core/pom.xml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,6 @@
7272
<version>${reactor.version}</version>
7373
<scope>test</scope>
7474
</dependency>
75-
<dependency>
76-
<groupId>org.awaitility</groupId>
77-
<artifactId>awaitility</artifactId>
78-
<version>${awaitility.version}</version>
79-
<scope>test</scope>
80-
</dependency>
8175
<dependency>
8276
<groupId>com.google.jimfs</groupId>
8377
<artifactId>jimfs</artifactId>

spring-shell-docs/modules/ROOT/nav.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
** xref:customization/logging.adoc[]
5757
** xref:customization/contextclose.adoc[]
5858
* xref:execution.adoc[]
59+
* xref:testing.adoc[]
5960
* Appendices
6061
** xref:appendices/techintro/index.adoc[]
6162
*** xref:appendices/techintro/parser.adoc[]
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
[[shell-testing]]
2+
= Testing
3+
4+
Spring Shell provides several utilities to facilitate testing of shell applications. These utilities help simulate user input, capture output, and verify command behavior in a controlled environment.
5+
6+
== Test assertions
7+
8+
Spring Shell offers the following test assertion APIs to validate command execution and output:
9+
10+
- `ShellScreen`: This class represents the shell screen and allows you to capture and analyze the output displayed to the user.
11+
- `ShellAssertions`: This class provides static methods to assert the results of shell command executions.
12+
- `ShellTestClient`: This class allows you to simulate user input and execute shell commands programmatically.
13+
14+
Here is an example of how to use these APIs in a test:
15+
16+
[source,java]
17+
----
18+
@ExtendWith(SpringExtension.class)
19+
class ShellTestClientTests {
20+
21+
@Test
22+
void testCommandExecution(@Autowired ShellTestClient shellTestClient) throws Exception {
23+
// when
24+
ShellScreen shellScreen = shellTestClient.sendCommand("test");
25+
26+
// then
27+
ShellAssertions.assertThat(shellScreen).containsText("Test command executed");
28+
}
29+
}
30+
----
31+
32+
== Test annotations
33+
34+
Spring Shell provides the `@ShellTest` annotation which is used to indicate that a test class is a Spring Shell test. It sets up the necessary context for testing shell commands. This annotation is defined in the `spring-shell-test-autoconfigure` module, and is designed to be used with Spring Boot applications.
35+
36+
Once you define your Spring Boot application class, you can create a test class annotated with `@ShellTest` to test your shell commands. Here is an example:
37+
38+
[source,java]
39+
----
40+
@SpringBootApplication
41+
public class ExampleShellApplication {
42+
43+
@Command(name = "hi", description = "Says hello")
44+
public String hello() {
45+
return "hello";
46+
}
47+
48+
}
49+
50+
@ShellTest
51+
@ContextConfiguration(classes = ExampleShellApplication.class)
52+
class ShellTestIntegrationTests {
53+
54+
@Test
55+
void testCommandExecution(@Autowired ShellTestClient client) throws Exception {
56+
// when
57+
ShellScreen shellScreen = client.sendCommand("hi");
58+
59+
// then
60+
ShellAssertions.assertThat(shellScreen).containsText("hello");
61+
}
62+
63+
@Test
64+
void testUnknownCommandExecution(@Autowired ShellTestClient client) {
65+
Assertions.assertThatThrownBy(() -> client.sendCommand("foo"))
66+
.isInstanceOf(CommandNotFoundException.class);
67+
}
68+
69+
}
70+
----

spring-shell-docs/pom.xml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,18 @@
2424
<groupId>org.springframework.shell</groupId>
2525
<artifactId>spring-shell-test-autoconfigure</artifactId>
2626
<version>${project.parent.version}</version>
27+
<scope>test</scope>
2728
</dependency>
2829
<dependency>
29-
<groupId>org.junit.jupiter</groupId>
30-
<artifactId>junit-jupiter</artifactId>
31-
<version>${junit-jupiter.version}</version>
30+
<groupId>org.springframework.shell</groupId>
31+
<artifactId>spring-shell-jline</artifactId>
32+
<version>${project.parent.version}</version>
3233
<scope>test</scope>
3334
</dependency>
3435
<dependency>
35-
<groupId>org.awaitility</groupId>
36-
<artifactId>awaitility</artifactId>
37-
<version>${awaitility.version}</version>
36+
<groupId>org.junit.jupiter</groupId>
37+
<artifactId>junit-jupiter</artifactId>
38+
<version>${junit-jupiter.version}</version>
3839
<scope>test</scope>
3940
</dependency>
4041
</dependencies>

spring-shell-test-autoconfigure/pom.xml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,15 @@
5252
<version>${junit-jupiter.version}</version>
5353
</dependency>
5454

55-
<!-- Test dependencies -->
55+
<!-- Optional dependencies -->
5656
<dependency>
57-
<groupId>org.awaitility</groupId>
58-
<artifactId>awaitility</artifactId>
59-
<version>${awaitility.version}</version>
60-
<scope>test</scope>
57+
<groupId>org.springframework.shell</groupId>
58+
<artifactId>spring-shell-jline</artifactId>
59+
<version>${project.parent.version}</version>
60+
<optional>true</optional>
6161
</dependency>
62+
63+
<!-- Test dependencies -->
6264
<dependency>
6365
<groupId>org.hibernate.validator</groupId>
6466
<artifactId>hibernate-validator</artifactId>

spring-shell-test-autoconfigure/src/main/java/org/springframework/shell/test/autoconfigure/AutoConfigureShell.java

Lines changed: 0 additions & 42 deletions
This file was deleted.

spring-shell-test-autoconfigure/src/main/java/org/springframework/shell/test/autoconfigure/AutoConfigureShellTestClient.java

Lines changed: 0 additions & 40 deletions
This file was deleted.

spring-shell-test-autoconfigure/src/main/java/org/springframework/shell/test/autoconfigure/ShellAutoConfiguration.java

Lines changed: 0 additions & 156 deletions
This file was deleted.

0 commit comments

Comments
 (0)