'Is there any shortcut/command available to skip karma tests? like -DskipTests for Maven

I have created Maven Web application and I generally use

mvn clean install

So it execute npm install command as its one of the execution goal and then it run karma tests So my question is, is there any shortcut or command available to skip karma tests conditionally? Like we have -DskipTests for Maven project to skip tests.

Off course we can simply remove the npm run test from the package.json file but I want to skip tests using command.

pom.xml

<build>
    <plugins>
        <plugin>
            <groupId>com.github.eirslett</groupId>
            <artifactId>frontend-maven-plugin</artifactId>
            <version>1.5</version>
            <executions>
                <execution>
                    <id>npm install</id>
                    <goals>
                        <goal>npm</goal>
                    </goals>
                    <configuration>
                        <workingDirectory>web/app</workingDirectory>
                        <installDirectory>build</installDirectory>
                        <arguments>install
                            --registry=${npm.registry}
                        </arguments>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>



Solution 1:[1]

Since I am using the frontend-maven-plugin I had to add below execution to plugin.

                <executions>
                    <execution>
                        <id>javascript tests</id>
                        <goals>
                            <goal>karma</goal>
                        </goals>
                        <phase>test</phase>
                    </execution>
                </executions>

After that, just using -DskipTest build argument able to skip karma tests.

mvn clean install -DskipTests

enter image description here

Solution 2:[2]

  1. You can define a system property -Dmaven.test.skip=true to skip the unit test.

    mvn package -Dmaven.test.skip=true
    
  2. Define properties in pom.xml

    <properties>
        <maven.test.skip>true</maven.test.skip>
    </properties>
    
  3. Use -DskipTests in surefire plugin

    mvn package -DskipTests
    
  4. Define surefire plugin in pox.xml

    <plugin>
     <groupId>org.apache.maven.plugins</groupId>
     <artifactId>maven-surefire-plugin</artifactId>
     <version>3.0.0-M1</version>
     <configuration>
         <skipTests>true</skipTests>
     </configuration>
    </plugin>
    

Solution 3:[3]

use

mvn clean install -DskipTests

-DskipTests will skip the Karma tests. Please refer to the following snippet available at https://github.com/eirslett/frontend-maven-plugin "Skipping tests: If you run maven with the -DskipTests flag, karma tests will be skipped."

So, Front end test cases are getting executed under "frontend-maven-plugin" which seems to recognize only -DskipTests to skip test cases execution unlike "maven-surefire-plugin" which recognizes both "-DskipTests" as well as "-Dmaven.test.skip=true" command parameters. So, if we use -DskipTests rather -Dmaven.test.skip=true command parameters, both backend as well as front end test cases get skipped.

This is what has been tested locally using -DskipTests Skip FE Tests

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ganesh Thorat
Solution 2 Codemaker
Solution 3