In order to write integration tests that verify whether running a compiled project.jar file yields the desired results, I thought of doing:

  1. Execute a J-unit test that substitutes certain files with test files
  2. Runs the Main of the project.
  3. AssertTrue on certain output file modifications.

However the 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).

Approach 0.

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.

Approach 1.

  1. I will look up how I can auto-compile a project while running the project.
  2. 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.ps1 in the Eclipse JUnit test, compile the project from the test to project.jar, open launchWSL.ps1 from the test, then make launchWSL.ps1 launch WSL in it and make it execute the compiled .jar with a command in powershell in wsl, and then detect when that project.jar is completed, copy the output files from WSL Ubuntu to the Eclipse working path and let eclipse loop scan for those files, and execute the Asserts when it detects those files.

  3. 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?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.