Scenario
After having written an integration test in in JUnit 5, that executes the compiled project.jar
, I used to manually compile the project after modifications, then manually execute the integration test. However, it is part of an click once installation, which automates the project compilation and execution using Gradle.
And to build the project.jar
with Gradle whilst evaluating JUnit integration test can be seen as a chicken and egg dilema; I compile the project so that I can run the integration test so that I can compile the project.
Solution
And gradle allows a build command to be run without testing the Unit-tests: gradle build -x tests
hence I can compile the project without tests, then compile the project again using: gradle build
which evaluates the integration test with the previously compiled version.
However, I feel like it may defeat the purpose of testing if you compile and run an untested compilation of project.jar
for an integration test, in order to compile a tested project.jar
Question
What is a better way/protocol to deal with the compilation-integration test interdependence?
Adressing Comments
The project structure consists of the Maven Standard Directory Layout supplemented with separate /src/integTest/java
and /src/integTest/resources
folders. The complete project directory tree consists of:
├───.gradle
│ ├───5.4
│ │ ├───executionHistory
│ │ ├───fileChanges
│ │ ├───fileContent
│ │ ├───fileHashes
│ │ ├───javaCompile
│ │ └───vcsMetadata-1
│ ├───5.5.1
│ │ ├───executionHistory
│ │ ├───fileChanges
│ │ ├───fileContent
│ │ ├───fileHashes
│ │ ├───javaCompile
│ │ └───vcsMetadata-1
│ ├───buildOutputCleanup
│ └───vcs-1
├───.settings
├───bin
│ ├───default
│ │ └───customsortserver
│ ├───main
│ │ └───customsortserver
│ └───test
│ └───customsortserver
├───build
│ ├───classes
│ │ └───java
│ │ └───main
│ ├───generated
│ │ └───sources
│ │ └───annotationProcessor
│ │ └───java
│ │ └───main
│ └───tmp
│ └───compileJava
├───gradle
│ └───wrapper
└───src
├───integTest
│ ├───java
│ │ └───customsortserver
│ └───resources
│ ├───originalData
│ ├───testDataSets
│ │ ├───backlog
│ │ └───pending
│ ├───testOutput
│ ├───wslCommandScripts
│ └───wslLaunchers
├───main
│ ├───java
│ │ └───customsortserver
│ └───resources
└───test
├───java
│ └───customsortserver
└───resources
Where the /src/integTest/resources/wslLaunchers
contain a powershell script that executes the compiled .jar
file half way in the integration test.
src/main/java
and tests insrc/test/java
? I'm trying to picture how your build is set up to fit the question you pose. If that were the case, then the tests are executed as part of the build (but the tests remain separate).integTest.dependsOn jar
to yourbuild.gradle
? (replaceintegTest
with the name of your integration test task) That will make sure the jar is available at the point where your integration tests are run, you would then need to tweak your powershell script to run the jar from the correct location under thebuild
folder somewheredependsOn
appears to be designed to tackle the interdependence between integration test that depend on the compilation result, and testing during/before compilation. I have not yet found a source that can confirm it also functions for the.jar
that is being compiled itself, rather than a different.jar
and have not yet been able to include a parameterized integration test in mybuild.gradle
script. If it is verified, you can post it as an answer that I can accept.