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 8600181
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T01:33:35+00:00 2026-06-12T01:33:35+00:00

I have Junit 4.8.2 and maven 3 Some tests in my application should fail

  • 0

I have Junit 4.8.2 and maven 3
Some tests in my application should fail the build in case of failure and some of them shouldn’t (just report that the following optional tests failed)

How can I do it with junit and if I can’t then maybe testng can?

E.g. I have two test cases:

First is not really important and can failed because of connection timeout, service unavailability and so on so on. So if it fail, I don’t want to fail whole build, just to let user know about it and write to console

Second is really important one and if it fail – build should be failed as well

I know about @Ignore – it is not what I’m looking for, because I don’t want to skip any tests.

I know about @Category so if you know how to configure surefire plugin to say: if category com.me.Required – build should be failed in case of failure and if category com.me.Optional – build should not be failed

  • 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-12T01:33:37+00:00Added an answer on June 12, 2026 at 1:33 am

    Consider using the failsafe plugin for your tests that are allowed to fail and set the testFailureIgnore flag to true.

    To use the failsafe plugin you have to add the plugin to you pom

    <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>foo.bar</groupId>
        <artifactId>test</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    
        <dependencies>
            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>4.10</version>
            </dependency>
        </dependencies>
    
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-failsafe-plugin</artifactId>
                    <version>2.12.4</version>
                    <executions>
                        <execution>
                            <goals>
                                <goal>integration-test</goal>
                                <goal>verify</goal>
                            </goals>
                        </execution>
                    </executions>
                    <configuration>
                        <testFailureIgnore>true</testFailureIgnore>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    
    </project>
    

    The surefire plugin will per default execute test named like Test. The failsafe plugin will per default execute the test named like IT.

    Given the tests

    import static org.junit.Assert.*;
    
    import org.junit.Test;
    
    public class SurefireTest {
    
        @Test
        public void test() {
            assertTrue(true);
        }
    
    }
    

    and

    import static org.junit.Assert.*;
    
    import org.junit.Test;
    
    public class FailsafeIT {
    
        @Test
        public void test() {
            assertTrue(false);
        }
    
    }
    

    Running mvn install will now result in

    [INFO] Scanning for projects...
    [INFO]
    [INFO] ------------------------------------------------------------------------
    [INFO] Building test 0.0.1-SNAPSHOT
    [INFO] ------------------------------------------------------------------------
    [INFO]
    .
    .
    .
    -------------------------------------------------------
     T E S T S
    -------------------------------------------------------
    Running SurefireTest
    Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.062 sec
    
    Results :
    
    Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
    .
    .
    .
    -------------------------------------------------------
     T E S T S
    -------------------------------------------------------
    Running FailsafeIT
    Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.072 sec <<< FA
    ILURE!
    ...
    Results :
    
    Failed tests:   test(FailsafeIT)
    
    Tests run: 1, Failures: 1, Errors: 0, Skipped: 0
    .
    .
    .
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESS
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 3.174s
    [INFO] Finished at: Sat Sep 29 08:19:38 CEST 2012
    [INFO] Final Memory: 9M/245M
    [INFO] ------------------------------------------------------------------------
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In a maven project I have some junit tests where I need to refer
I have an extremely odd problem in my JUnit tests that I just can't
I'm using Maven 3.0.3. I want to run some Junit tests in my test
I am using embedded Apache Derby database for JUnit tests. I have some JPA
I have many JUnit tests, which are all created by Netbeans' assistant (so nothing
I have written JUnit tests for my class, and would like it to tell
I have web application on spring mvc and maven. When I execute mvn clean
I have a Java EE 6 Wicket application deployed with maven using IntelliJ IDEA
For tests of some small JBoss enterprise apps I would like to use JUnit,
I have a Maven (3.0.3) / GWT (2.4) project. I'm trying to write some

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.