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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:43:17+00:00 2026-05-22T16:43:17+00:00

I am implementing some tests for an existing Java Swing application, so that I

  • 0

I am implementing some tests for an existing Java Swing application, so that I can safely refactor and extend the code without breaking anything. I started with some unit tests in JUnit, since that seems the simplest way to get started, but now my priority is to create some end-to-end tests to exercise the application as a whole.

I am starting the application afresh in each test by putting each test method in a separate test case, and using the fork="yes" option in Ant’s junit task. However, some of the use cases I would like to implement as tests involve the user exiting the application, which results in one of the methods calling System.exit(0). This is regarded by JUnit as an error: junit.framework.AssertionFailedError: Forked Java VM exited abnormally.

Is there a way to tell JUnit that exiting with a return code of zero is actually OK?

  • 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-05-22T16:43:18+00:00Added an answer on May 22, 2026 at 4:43 pm

    How I deal with that is to install a security manager that throws an exception when System.exit is called. Then there is code that catches the exception and doesn’t fail the test.

    public class NoExitSecurityManager
        extends java.rmi.RMISecurityManager
    {
        private final SecurityManager parent;
    
        public NoExitSecurityManager(final SecurityManager manager)
        {
            parent = manager;
        }
    
        public void checkExit(int status)
        {
            throw new AttemptToExitException(status);
        }
    
        public void checkPermission(Permission perm)
        {
        }
    }
    

    And then in the code, something like:

    catch(final Throwable ex)
    {
        final Throwable cause;
    
        if(ex.getCause() == null)
        {
            cause = ex;
        }
        else
        {
            cause = ex.getCause();
        }
    
        if(cause instanceof AttemptToExitException)
        {
            status = ((AttemptToExitException)cause).getStatus();
        }
        else
        {
            throw cause;
        }
    }
    
    assertEquals("System.exit must be called with the value of " + expectedStatus, expectedStatus, status);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am going to start implementing some unit tests for a codebase that is
I am implementing an application that involves some svn functions. I'm gonna write some
I am implementing some networking stuff in our project. It has been decided that
I'm implementing some code generators, i would like to know if there's any way
in a bash script I am implementing some functions, that take parameters The problem
I have an existing VS 2005 Std .NET Compact Framework application that I want
I have a rails application that I am implementing the Twilio SMS API on,
I'm attempting to run some unit tests on my application using SQLite in memory,
I am buiding an application in Java that connects to a variety of databases,
Given that some of the advice for implementing CQRS advocates fairly close-to-the-metal query implementation,

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.