New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
System.in and System.exit do not work together within the same test #14
Comments
The test Unfortunately I cannot reproduce the problem of public class Gh14App {
public static void main(String... args) throws Exception {
String output = args [0] + System.in.read() + args[1];
System.out.write(output.getBytes());
System.exit(0);
}
} and wrote a test public class Gh14AppTest {
@Rule
public final ExpectedSystemExit exit = ExpectedSystemExit.none();
@Rule
public final TextFromStandardInputStream systemInMock = emptyStandardInputStream();
@Rule
public final StandardOutputStreamLog log = new StandardOutputStreamLog();
@Test
public void testJob() throws Exception {
systemInMock.provideText("A");
exit.expectSystemExitWithStatus(0);
Gh14App.main("pre", "post");
assertThat(log.getLog(), is(equalTo("preApost")));
}
} This test runs successfully. How do you read the input from |
Thanks for the quick response! I'm a little curious about the assertion in @Test
public void testJob() throws Exception {
systemInMock.provideText("A");
exit.expectSystemExitWithStatus(0);
exit.checkAssertionAfterwards(new Assertion() {
public void checkAssertion() {
assertThat(log.getLog(), is(equalTo("preApost")));
}
});
Gh14App.main("pre", "post");
} does the test still pass? Does it fail if you change to cat dat.csv | java -cp myJar.jar CommandLineRunner works just fine. |
You're right concerning the assertion stuff. But |
If your code reads from the File IMHO you should use the Java abstraction |
Thanks so much for looking into this. I really appreciate you effort. It seems clear that the problem is in how I handle |
It is my pleasure to help you. |
I'm attempting to test a command line runner (based on Spring Batch). Unfortunately, the runner exits rather than, say, returning a value to a trivial wrapper method that exits with that value. In any case, I'd also like to pass data by piping it in through stdin. I can confirm this works in a stand-alone application. However, the mocked data I'm passing into
systemInMock
doesn't seem to make it to themain
method. My code looks something like the followingThanks for writing such an awesome tool! Even with this issue, it has still helped me tremendously!
The text was updated successfully, but these errors were encountered: