Open ghost opened 6 years ago
oh, while I was writing this - how I solved it with Spring Shell 2.0.0.M1 - I updated my application to 2.0.0.RELEASE and let the build run - and I go back and it doesn't work anymore. It hangs like it's written in the documentation...
So, I need to investigate what changed since then....
OK, I see, in this commit f90edd42c41c738ed628805922c850c9b05c6730
you changed from
@ConditionalOnMissingBean(ApplicationRunner.class)
to
@ConditionalOnProperty(prefix = SPRING_SHELL_INTERACTIVE, value = InteractiveShellApplicationRunner.ENABLED, havingValue = "true", matchIfMissing = true)
and
@ConditionalOnProperty(prefix = SPRING_SHELL_SCRIPT, value = ScriptShellApplicationRunner.ENABLED, havingValue = "true", matchIfMissing = true)
....which actually makes it even simpler by adding these properties to the @SpringBootTest
annotation. Then the custom ApplicationRunner
is no longer needed.
Minimalistic example (without imports):
@RunWith(SpringRunner.class)
@SpringBootTest(properties = {
InteractiveShellApplicationRunner.SPRING_SHELL_INTERACTIVE_ENABLED + "=false",
ScriptShellApplicationRunner.SPRING_SHELL_SCRIPT_ENABLED + "=false"
})
public class MyShellTests {
@Autowired
private Shell shell;
@Test
public void contextLoads() {
Object help = shell.evaluate(() -> "help");
assertNotNull(help);
System.out.println(help);
}
}
In the main documentation it says:
But I have solved it in my project differently and got the test running using this:
In my main test class I import an
ApplicationRunner
class that basically exits right away. Given the highest priority, it is chosen over the default Spring Shell runner.Here is the
TestShellApplicationRunner
classI left out the imports for brevity.
This way, the test runs, you can even execture command, like I do here with the help command, and make asserts and the test exits cleanly.
I think it would be a good idea to include this way in the general approach and then the warning above can be removed and replaced with this suggestion on how to test the Spring Shell commands.
-Stefan