0

I am running a set of tests using junit and I have created a maven project for it. I use the surefire plugin to run the tests. I wanted to package this project as a self executable jar for the sake of convenience.So I placed all of test classes in the src/main/java directory as recommended for using the maven shade plugin for generating an uber jar. I created a class with a main method and use maven invoker to execute my tests. The tests get executed perfectly when I use my ide to run the main method. However, after I package it as a jar , the invoker is unable to locate the pom.xml. If I place a copy of the pom.xml in the same directory as the jar, maven is invoked but it is unable to execute the tests as surefire is unable to locate the tests.

I would love to know if there is a solution for this or if there is a better approach towards trying to achieve my goal.

@khmarbaise and everyone else trying to help me , let me describe my scenario a little more in detail. Lets take any api , for example , lastfm api, I would be writing classes for each api end point and every method in each class would be a test. I use junit to execute the tests. I use a junit wrapper called serenity bdd that helps me structure my tests and generate aggregate reports. The maven goal serenity:aggregate would generate an aggregated report of all tests. I am using the maven invoker to run tests using surefire plugin and then aggregate the tests using serenity. In my eclipse project I simply create a maven run configuration and provide the maven goals. Or else I would use the terminal to run maven from my project base directory. Apart from my class file, I have several resources, like csv files which are inputs for parametric tests a log folder where all log files that are generated get saved and other sample files for testing file upload apis. I felt that it would be simple to package all of this as a jar and let my developers add this jar as a dependency and run a simple script which runs the jar each time they create and deploy a build. Getting the pom file for invoking maven was trivial in case of eclipse or the command line but not so straight forward when its inside of a package.

Nakp1
  • 1
  • 1
  • Are you testing a plugin? It's not clear what kind of application your are trying to test? And why you are not using usual integration tests ? – khmarbaise Oct 16 '19 at 17:49
  • The surefire plugin is meant to run tests during the build. Why do you want to create a standalone jar for this? – J Fabian Meier Oct 16 '19 at 17:50
  • @khmarbaise I'm not testing a plugin, I'm testing a set of apis. – Nakp1 Oct 16 '19 at 17:58
  • Can you give a real example of what kind of App you are trying to test ? And what kind of tests you are trying to write? – khmarbaise Oct 16 '19 at 18:00
  • @JF Meier I am using a maven plugin whose (maven)goal is generating the reports after all tests have completed. – Nakp1 Oct 16 '19 at 18:01
  • @khmarbaise I have updated my parent post description with more details. – Nakp1 Oct 16 '19 at 18:26
  • Why don't you just include the tests into the project that builds the api? – J Fabian Meier Oct 16 '19 at 18:35
  • @JF Meier I wish to deploy the build to be tested in a staging environment and then run the tests once the build is successfully deployed. – Nakp1 Oct 16 '19 at 18:58

0 Answers0