I'm trying to have some end-to-end test for the component I'm developing using Java. So, these classes in test are not Unit Tests, and I only want to run them as a normal Java class.
I have my sources in the src\main\java folder and the tests inside src\test\java. The test has two Java classes, one is a util class and the other one extends a class in main and also has the main method. Ultimately, I need to run this main method.
I created two pom files, one for the main project and one for running the test. The only difference in the test pom file was the mainClass property. When I had the test classes inside src\main\java, maven compiles them and I was able to run them without any issue.
Because having tests inside the src\main\java folder is a bad practice, I wanted to move it to the src\tests\java folder. But then it doesn't work. It compiles the project but doesn't compile the test classes (obviously because now it's not inside the src\main\java folder). So I added the test to the classpath scope in the test pom file as below.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<configuration>
<mainClass>com.my.company.project.MyTestClass</mainClass>
<classpathScope>test</classpathScope>
</configuration>
</plugin>
But this doesn't work.
So I tried the solution provided by maven itself, but it's the same. It creates the jar file with my test class as the main class in the manifest file. But there are is no such class, nor classes from the main inside of the jar file. And I get the below error when running the jar file.
Could not find or load main class com.my.company.project.MyTestClass
My end goal is to be able to compile and run my Test class (to test the main class) using maven.
Can you suggest me a way to achieve this?
Aucun commentaire:
Enregistrer un commentaire