In order to write integration tests that verify whether running a compiled
project.jar file yields the desired results, I thought of doing:
- Execute a J-unit test that substitutes certain files with test files
- Runs the Main of the project.
- AssertTrue on certain output file modifications.
main is written to be compiled in eclipse, and opened/ran manually from WSL Ubuntu 18.04. So running
main from eclipse in windows will not work (It manipulates environment variables and uses input/output piping for several commands that are run in WSL Ubuntu 18.04 so emulating the behavior of WSL for Java testing becomes significantly more difficult than the entire project itself).
I run the test but do not run the main from the test. Then I manually compile the project, then I manually open up WSL Ubuntu 18.04, then I manually run the
java -jar project.jar file.` And then manually inspect the output files.
- I will look up how I can auto-compile a project while running the project.
After reading https://stackoverflow.com/questions/50108739/how-do-i-sequentially-execute-wsl-commands-from-java and https://www.brianketelsen.com/getting-crazy-with-windows-subsystem-for-linux/ I am researching how I can open the WSL Ubuntu 18.04 terminal from java.
2.1 One approach I've found is to create a powershell script
launchWSL.ps1in the Eclipse JUnit test, compile the project from the test to
launchWSL.ps1from the test, then make
launchWSL.ps1launch WSL in it and make it execute the compiled
.jarwith a command in powershell in wsl, and then detect when that
project.jaris completed, copy the output files from WSL Ubuntu to the Eclipse working path and let eclipse loop scan for those files, and execute the
Assertswhen it detects those files.
- I need to find a solution to grasp/maintain control over that launched instance of the WSL Ubuntu 18.04 terminal, so that the test method can execute commands and read the output files from within that instance, since windows is not able to access those output files.
What would be a better/the preferred strategy to test this project?