Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8072161
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T13:55:45+00:00 2026-06-05T13:55:45+00:00

I have the same problem as Junit4 and TestNG in one project with Maven

  • 0

I have the same problem as Junit4 and TestNG in one project with Maven but I still have issues.
I created simple project where I need to use junit4 and testng
Here is root pom:

    <groupId>com.dimas.testmodule</groupId>
            <artifactId>TheParent</artifactId>
            <version>0.0.001</version>
            <name>TheParent</name>
            <packaging>pom</packaging>

            <properties>
                <spring.version>3.0.5.RELEASE</spring.version>
                <spring.scope>test</spring.scope>
                <maven.surefire.plugin.version>2.9</maven.surefire.plugin.version>
            </properties>

            <dependencies>
                <dependency>
                    <groupId>junit</groupId>
                    <artifactId>junit</artifactId>
                    <version>4.7</version> 
                       <scope>test</scope>
                    </dependency>
        ...etc
                </dependencies>

            <build>
                <finalName>${project.artifactId}</finalName>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-compiler-plugin</artifactId>
                        <version>2.3.2</version>
                        <configuration>
                            <source>1.6</source>
                            <target>1.6</target>
                        </configuration>
                    </plugin>
                </plugins>
            </build>

            <profiles>
                <profile>
                    <id>default</id>
                    <activation>
                        <activeByDefault>true</activeByDefault>
                    </activation>
                    <modules>
                        <module>JUnitOnly</module>
                        <module>TestNGOnly</module>
                        <module>testmodule</module>
                    </modules>
                    <build>
                        <plugins>
                            <plugin>
                                <groupId>org.apache.maven.plugins</groupId>
                                <artifactId>maven-surefire-plugin</artifactId>
                                <version>${maven.surefire.plugin.version}</version>
                                <configuration>
                                    <redirectTestOutputToFile>false</redirectTestOutputToFile>
<excludes>
                                <exclude>**/*NGTest.java</exclude>
                            </excludes>
                                </configuration>
                            </plugin>
                        </plugins>
                    </build>
                </profile>

                <profile>
                    <id>testNGonly</id>
                    <modules>
                        <module>JUnitOnly</module>
                        <module>TestNGOnly</module>
                        <module>testmodule</module>
                    </modules>

                    <build>
                        <plugins>
                            <plugin>
                                <groupId>org.apache.maven.plugins</groupId>
                                <artifactId>maven-surefire-plugin</artifactId>
                                <version>${maven.surefire.plugin.version}</version>
                                <configuration>
                                    <redirectTestOutputToFile>false</redirectTestOutputToFile>
                                    <includes>
                                        <include>**/*NGTest.java</include>
                                    </includes>
                                </configuration>
                            </plugin>
                        </plugins>
                    </build>
                </profile>
            </profiles>

modules JUnitOnly and TestModule just inherits and do not overrite any properties. And here are TestNgOnly

<groupId>com.dimas.testmodule.testngonly</groupId>
    <artifactId>TestNGOnly</artifactId>
    <version>0.0.001</version>
    <name>testngonly</name>
    <parent>
        <groupId>com.dimas.testmodule</groupId>
        <artifactId>TheParent</artifactId>
        <version>0.0.001</version>
    </parent>

    <dependencies>
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>6.3.1</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>

    <profiles>
        <profile>
            <id>testNGtest</id>  
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <version>${maven.surefire.plugin.version}</version>
                        <configuration>
                            <redirectTestOutputToFile>false</redirectTestOutputToFile>
                            <suiteXmlFiles>
                                <suiteXmlFile>
                                    <!--test/resources/my-testng.xml-->
                                    src\test\resources\my-testng.xml
                                </suiteXmlFile>
                            </suiteXmlFiles>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>

Well I need to ignore testng tests for default profile and launch only testng tests for profile testNGOnly.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T13:55:46+00:00Added an answer on June 5, 2026 at 1:55 pm

    There are three modules – junit, testng and mixed.

    The default profile should execute only junit tests – i.e. run junit module and run junit tests of mixed module. testNG profile should execute only testNG tests – i.e. run testNG module and run testNG tests of mixed module.

    The way profiles work in maven, it is not possible to exclude a module in a profile. However, there is no need to build a module which is not required.

    Thus, in default profile, have modules junit and mixed.

    In testNG profile, add module testNG.

    Following maven best practice, define <dependencies> in the parent pom within <dependencyManagement>. This allows us to only use junit dependency in junit module and testNG dependency in testNG module.

    There is nothing common about surefire configuration across the three modules and as such not required to be specified in parent pom.

    Since it not required to run junit tests in testNG profile, add a plugin configuration to skipTests in testNG profile for junit module.

    Configure the mixed pom using the tip in this answer for the related SO question. This gets tricky since surefire needs to use junit or testng runner based on the profile.

    I have incorporated the above suggestions in a sample project here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the same problem described here on the e-office blog , but in
i have same problem. other files doc, xls uploads fine. but pdf uploading gives
I have the same problem but a little different from Neil problems ( Error
I have this same problem, but the solution presented isn't working, nor is any
I just read this question I have same problem too, but I wanted more.
I have the same problem as described in ( Last record of Join table
I have the same problem as in the following post . So I am
Solution: if you have the same problem, addElement() instead of addChild() is what did
Does anyone have the same problem as I do? ... I've upgraded to the
I have essentially the same problem discussed here: http://khason.net/blog/dependency-property-getters-and-setters-in-multithreaded-environment/ public static readonly DependencyProperty MyPropertyProperty

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.