These tests should run after the jar file is built. They should test whether it runs at all, and whether it produces correct console output given certain input files.
Could you point at some examples of such tests for console applications? Do these test have to be written in Java to be used with Maven?
There is a similar question (Testing console based applications/programs - Java) but what I need is blackbox testing, not unit testing. And it does not mention Maven.
UPDATE:
It turned out that it vas very easy to do. My first problem was a misconception of integration tests after seeing so many definitions here (What is Unit test, Integration Test, Smoke test, Regression Test?; What's the difference between unit, functional, acceptance, and integration tests?; What are unit testing and integration testing, and what other types of testing should I know about?; What is an integration test exactly?). The second problem was that I did not intend to write these test in Java, but in the end I had to learn how to use java.lang.Runtime
.
First of all, I have added this to my pom.xml:
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
Then I have created an *IT.java file in src/test/java:
public class MyAppIT {
@Test
public void test() throws IOException {
Runtime runtime = Runtime.getRuntime();
String cmd = "java -cp target/myapp.jar my.app.Main";
Process process = runtime.exec(cmd);
InputStreamReader isr = new InputStreamReader(process.getErrorStream());
BufferedReader br = new BufferedReader(isr);
Boolean containsUsage = false;
String line;
while ((line = br.readLine()) != null) {
if (line.contains("Usage")) {
containsUsage = true;
}
}
assertTrue(containsUsage);
}
}
Now I use mvn verify instead of mvn package.
Results :
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0