0

Sorry Im newbie in Java and I wonder how to avoid test execution of my dependencies projects.

I have a Proj3 which has two dependencies, Proj1 and Proj2 (among other things).

If I execute mvn clean install not only execute tests of my current Proj3 but also from my dependencies Proj1 and Proj2.

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.proj.environment.tests.api</groupId>
<artifactId>environment_Api_Tests</artifactId>
<version>437r21</version>
<packaging>pom</packaging>

<properties>
    <cucumber.version>4.3.1</cucumber.version>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.version>437r21</project.version>
</properties>

<dependencies>
    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-java</artifactId>
        <version>${cucumber.version}</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-junit</artifactId>
        <version>${cucumber.version}</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.12</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>com.proj.environment</groupId>
        <artifactId>Proj1</artifactId>
        <version>${project.version}</version>

    </dependency>

    <dependency>
        <groupId>com.proj.environment</groupId>
        <artifactId>Proj2</artifactId>
        <version>${project.version}</version>

    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.7.0</version>
            <configuration>
                <encoding>UTF-8</encoding>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.18.1</version>
            <configuration>
                <testFailureIgnore>true</testFailureIgnore>
                <includes>
                    <exclude>**/*Test.java</exclude>
                </includes>
            </configuration>
        </plugin>
    </plugins>
</build>

<modules>
    <module>../Proj1</module>
    <module>../Proj2</module>        
</modules>

Many thanks,

CABascourt
  • 1,407
  • 2
  • 14
  • 18
  • This makes sense; at an integration level you want the tests of your lower modules to pass before you depend on them, otherwise you're depending on unstable code. Now, the question is - are you okay with not running *any* tests? – Makoto Aug 29 '19 at 22:59
  • You only want to build proj3 right ? – Arnaud Claudel Aug 29 '19 at 23:02
  • Yes, I only need to run build and run tests for project 3. – CABascourt Aug 30 '19 at 01:07
  • use `-DskipTests=true` for skipping all tests or see [link](https://stackoverflow.com/questions/9123075/maven-how-can-i-skip-test-in-some-projects-via-command-line-options) – belbix Aug 30 '19 at 13:16

1 Answers1

0

The POM you are showing is for environment_Api_Tests project which is aggregation (parent) project. That means

... if a Maven command is invoked against the parent project, that Maven command will then be executed to the parent's modules as well.

Thus it is not very clear what exactly is your case. Depending on what it has to do with the Proj3 you mentioned, there are different answers:

If the environment_Api_Tests project (the POM you posted) is what you call Proj3

It is perfectly normal to execute commands against its modules (do not confuse it with dependencies) and it really makes no sense to exclude tests from modules. Moreover you can not have tests in aggregation (parent) project itself. So if you only want to execute some modules, then it's best to introduce another aggregation project with only those modules. You can further aggregate aggregation projects.

The <dependencies> here have nothing to do with that. The only thing that section does in a aggregation project is to provide dependencies for all <modules>. In your case that means that:

  • Proj1 depends on Proj1 and Proj2.
  • Proj2 depends on Proj1 and Proj2.

which is probably not what you want!

If there is another Proj3 that is also a module in environment_Api_Tests

Then you just need to execute the tests on that project and not on environment_Api_Tests. Even if Proj3 depends on Proj1 and Proj2 their tests will not be executed

If Proj3 is environment_Api_Tests but it was not meant to be an aggregation project

Then you need to change the packaging from pom to jar (or whatever your target is) and remove the <modules> but keep the <dependencies>. That way the project can have own tests and will not execute tests of dependencies.

Note on test dependencies

One thing to keep in mind is how test dependencies work in multi-module projects. If tests in one module depends on tests in another module, you will have to create a jar containing test classes.

Milen Dyankov
  • 2,972
  • 14
  • 25