When unit testing with Ivy, is it best practice to put the test dependencies into the Ivy.xml file for the target binary you are building? Or should they be in a separate Ivy.xml file for the test project you are building?
I’m using Ant build files on my Jenkins build server.
Originally I planned to run the Unit test project after the target binary’s build, but then my uploads to Artifactory got confused as the last ivy resolve was done for the test dependencies, not the target binary.
If I place the test dependencies in the actual binary’s Ivy.xml, I get the following error:
“a module is not authorized to depend on itself”
…but my test depends on the target binary that I’m building.
Should the test project’s Ivy.xml file not actually list the target binary as a dependency?
Update
I have the dependencies now in the target binary’s Ivy.xml.
I’ve flagged the new depencencies as having a “test” configuration to set them apart from the dependencies needed for the target binary.
I’m now working out how to point my test project at the binary produced by the build of the target project. I’m not sure if this is technically an issue with Ivy.
After I build the target binary, should I have a relative path reference from the test project to the target binary?
Another idea is to publish the target binary to the local cache, and then reference it from there in the target project.
Update 2
I ended up using the ant copy task to copy the binary built from target project to the folder with the target project’s dependencies in it. Since the test project dependencies are in this folder, the target project can locate the target binary.
Agreeing with Mark O’Connor’s comment:
Best practice with unit testing in general is to run the tests on the compiled code before packaging it.
I would recommend including your call to your unit tests as a step after compilation, and before packaging. Most of the time, you don’t want to package and upload code to an artifact manager if it has failing tests (unless you have some form of special circumstances).
All of this implies that the tests should occur in the same Jenkins job. You can build both DLL’s, have them refer to each other using relative paths, and execute tests, all in the same job. Then you can upload your binary to Artifactory, confident that it passes tests.