0

I have a Java program that has a command line interface using Commons CLI and processes an input file and writes an output file.

I use JUnit to test objects and their methods. However, I wonder if there is a possibility to test my whole compiled program with JUnit or any other way inside the tool rather than write an own test suite program as a seperate Java project.

What I would like to do:

  1. Load an input file test.txt from a defined directory inside the Java project
  2. Call the program: java -jar -enableassertions MyTool.jar -i \Path\To\Test\test.txt
  3. See if any errors or assertions are thrown
  4. Repeat this for multiple test input files
raedma
  • 293
  • 1
  • 12
  • 2
    Yes - but you don't need to call `java -jar`. Store your test files on the classpath; then loop over them and create [parameterised tests](https://github.com/junit-team/junit4/wiki/parameterized-tests). In each test, write the file from the classpath to a temp location then invoke `main()` with a `String[]` containing `-i` and the full path to your temp location. – Boris the Spider Sep 15 '16 at 10:03
  • First of all, JUnit ist just a tool to drive testcases in an automated fashion; so of course: you can use for such things ... so, simply spoken, the answer is "yes", sure. – GhostCat Sep 15 '16 at 10:04
  • You can have a shell script / batch file that generates output, even capturing standard output and error with ` >out.txt 2>err.txt` and do a file compare with the expected output. – Joop Eggen Sep 15 '16 at 10:33

0 Answers0