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

  • Home
  • SEARCH
  • 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 1019005
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T10:56:38+00:00 2026-05-16T10:56:38+00:00

I am creating a custom test runner for JUnit test cases using JUnitCore’s run(junit.framework.Test

  • 0

I am creating a custom test runner for JUnit test cases using JUnitCore’s run(junit.framework.Test test) and passing in ClassName.suite(). My tests run, however the results returned are null. It seems that objects are not being initialized in the setUp() method cause setUp() apparently is never called as it should, even with the @Before annotation. The tests are successful if I instantiate each object required within each test method. This approach however is tedious and defeats the purpose of having a test class. Is this behavior normal? Are there better test runners out there for JUnit that reflect the same behavior as the test runner in Eclipse? Thanks.

Here is the code for the runner:

public class TestRunner
{
    Result res = new Result();
    String results = new String();
    JUnitCore runner = new JUnitCore();

    protected TestRunner()
    {
    }

    public String runReport(Test input)
    {
        System.out.println(input.toString());
        res = runner.run(input);
        String testClass = "Class: ";
        String testFailCt = "Failure Count: ";
        String testFalures = "Failures: ";
        String testRunCt = "Runs: ";
        String testRunTm = "Run Time: ";
        String testSuccess = "Success: ";
        String newln = "\n";
        results += testClass + input.getClass() + newln;
        results += testFailCt + res.getFailureCount() + newln;
        results += testFalures + newln;
        List<Failure> failures = res.getFailures();
        int i = 0;
        for (Failure x: failures)
        {
            i++;
            results += i +": " + x + newln;
        }
        results += testRunCt + res.getRunCount() + newln;
        results += testRunTm + res.getRunTime() + newln;
        results += testSuccess + res.wasSuccessful() + newln;
        return results;
    }
}

Here is how the runReport() method is being called from another class:

runner.runReport(TestClassName.suite());

What should I pass into run() so that setUp() will be implicitly called before each test? I know passing in the suite will not do so. Therefore, I just altered my test cases so that all necessary objects are instantiated within each test.

  • 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-16T10:56:38+00:00Added an answer on May 16, 2026 at 10:56 am

    … setUp() apparently is never called as it should, even with the @Before annotation.

    JUnit version 4 has annotation support – I think junit.framework indicates that you are using Version 3.
    If you are running JUnit 4 tests using a JUnit 3 TestRunner, you might find these articles of interest:

    JUnit Test Runner that creates tests just before running them

    JUnit FAQ – see “Writing Tests” para. 3.

    An early look at JUnit 4

    Good luck!

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

Sidebar

Related Questions

I'm often creating custom assertion methods for my JUnit tests. eg: public void assertArrays(String[]
I'm working on creating a test suite that runs on multiple databases using dbunit
I've been creating unit tests using JUnit in Eclipse and the basic principles of
I'm creating custom UserControl in ASP.NET and I'm using System.ComponentModel.Attributes to decorate properties with
I am creating a custom control using C# GDI+. Quick explanation...the control will be
I am creating a custom testing application using PHPUnit and Goutte. I would like
I'm using the great .NET library AutoPoco for creating test and Seed Data. In
I am creating a custom .net hardware framework that will be used by other
I'm creating a custom control, part of which is using the Graphics class to
I am creating a custom doclet that I want to run in my Maven

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.