0

I'm using Azure DevOps for CI/CD and for CI portion, I want to package the entire project and the CD portion will execute the tests from the jars

I can't seem to generate the executables though. I am using PageObject model so my layout for my maven project is as such

---src/main/java

-------PageObject

---src/test/java

------>tests here

My goal in Azure DevOps is to make sure the code compiles and package up the tests and drop them into an artifact. The release will then run the tests from this artifact. I don't want to drop the entire repo into the artifact, rather just the binaries (so whatever is in the ~/target/ folder.

It seems that when I try to compile, there are not any jars that are created.

I do not want the CI portion to execute the tests; simiply package up the artifact is my goal here.

  • The IDE should have an option to output an executable .jar file(s). You can either bundle into one, or keep all jars separate. (you didn't mention which IDE you are using here...) You may also want to extract webdrivers at run-time (add them as resources) or use something like WebDriverManager that will download/install for you. – pcalkins Jun 22 '22 at 18:28
  • I am using Eclipse and yes using WebDriverManager to handle the drivers at runtime. I don't need the IDE but want to do it via command line (and using Azure Pipelines so it will be a command). I try running the created jar but get an error "no main manifest attribute" in my jar –  Jun 22 '22 at 18:31
  • I believe the manifest will say where the entry point is... The class that contains "main". I'd suggest using ant: https://ant.apache.org/manual/tutorial-HelloWorldWithAnt.html – pcalkins Jun 22 '22 at 18:35
  • It is only a project consistenting of tests - the application is seperate from the tests entirely. There is no "main" class. –  Jun 22 '22 at 18:39
  • there should be a "main" method. It'll be inside some class, but you need to tell the run-time what class it is in. (maybe it'll be in the framework that runs your test jars...) – pcalkins Jun 22 '22 at 18:43
  • 1
    Read this, I think that anything in /src/test/java will not be part of the package so I am not sure if I need to move everything to src/main/java which doesn't sound ideal https://stackoverflow.com/questions/16375489/how-to-package-test-classes-into-the-jar-without-running-them –  Jun 22 '22 at 18:45
  • ah... that looks like what you need there. Another option would be to include a copy of all your test jars in the resources for the main project. You will then have them available inside the build... if someone wanted to extract them they could. (Not sure why you'd want to do that though... ) – pcalkins Jun 22 '22 at 18:48
  • I think what I want is to simply generate the jar for the tests and then be able to run these tests. I try mvn package with the option -Dmaven.test.skip and with this option, it seems to skip the generation of the jar. If I remove this option, the jar is created but still have issues running it. Ideally, I want to skip the step of running the tests and generate the test-jar. –  Jun 22 '22 at 19:02
  • I'm guessing your using jUnit here... maybe see this thread: https://stackoverflow.com/questions/51894726/how-can-i-export-junit-test-cases-into-an-executable-jar – pcalkins Jun 22 '22 at 19:07
  • The thing is what if I have more than one test class? –  Jun 22 '22 at 19:09
  • btw, pushing those tests to the CI channel (assuming it's public) could be a security concern. (especially since you'll be downloading/writing webdriver executables) You may also want to re-phrase the question to get to the broader point here... why it is that you want to include the test jars. There may be another solution entirely. – pcalkins Jun 22 '22 at 20:04
  • It's a POC for now but I want the build to generate the jars and then pass the jars to the release to run the tests. It is not public so no issue there. –  Jun 22 '22 at 21:11
  • If they need to be executable jars, you need jUnit, since it sounds like main() is there. If not, you could just add the test folder as resources that can be extracted at run-time (if they don't currently exist) Still not sure of the bigger picture here. – pcalkins Jun 22 '22 at 21:17

0 Answers0