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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T22:05:34+00:00 2026-06-10T22:05:34+00:00

I have three JUnit test classes that all had some common code, including identical

  • 0

I have three JUnit test classes that all had some common code, including identical setup() methods. So, I factored this code out into its own class that extends TestCase and now have the three earlier JUnit test classes extend this new class. The new super class contains no tests itself.

However, in our build, JUnit runs all the JUnit test classes, including the new super class with no tests. It gives this error:

junit.framework.AssertionFailedError: No tests found in com.acme.ControllerTest

I could get rid of this error by creating some simple test that does nothing in ControllerTest. But is there a cleaner way of fixing this?

  • 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-10T22:05:36+00:00Added an answer on June 10, 2026 at 10:05 pm

    This works for me

    JUnit 3

    public abstract class BaseTest extends TestCase {
    
        public void setUp(){
            System.out.println("before called");
        }
    }
    
    public class Test1 extends BaseTest {
    
        public void test() {
            Assert.assertTrue(true);
            System.out.println("Test1");
        }   
    }
    
    public class Test2 extends BaseTest {
    
        public void test() {
            Assert.assertTrue(true);
            System.out.println("Test2");
        }   
    }
    

    The output I get is

    before called
    Test2
    before called
    Test1
    

    JUnit 4

    For JUnit4 you do not even need to make the base class abstract. You can just use the following

    public class BaseTest {
        @Before
        public void setUp(){
            System.out.println("before called");
        }
    }
    
    public class Test1 extends BaseTest {
        @Test
        public void test() {
            Assert.assertTrue(true);
            System.out.println("Test1");
        }   
    }
    
    public class Test2 extends BaseTest {
        @Test
        public void test() {
            Assert.assertTrue(true);
            System.out.println("Test1");
        }   
    }
    

    I would strongly recommend using JUnit 4. Using annotations means that you break some of this inheritance dependency which can get confusing.

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

Sidebar

Related Questions

I have a JUnit test case in an Android project that contains code that
I have three classes that I am using and have shortened for ease of
I want to run unit tests (Junit) on some model classes that typically will
I have a java package which contains all my test case classes. Each class
I have a base class for many tests that has some helper methods they
I have a JUnit test that tests adding Strings to a Dictionary custom type.
Have three classes User, Group and Field. Many to many relationship on User /
Have three divs in a container that I want to float over a large
i have three java based web application app1,app2 and app3 at production. All 3
I have three divs, within a content div. Container width 70%. Within that I

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.