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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T20:21:12+00:00 2026-05-16T20:21:12+00:00

I’m using Spring 3.0.4 and JUnit 4.5. My test classes currently uses Spring’s annotation

  • 0

I’m using Spring 3.0.4 and JUnit 4.5. My test classes currently uses Spring’s annotation test support with the following syntax:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration (locations = { "classpath:configTest.xml" })
@TransactionConfiguration (transactionManager = "txManager", defaultRollback = true)
@Transactional
public class MyAppTest extends TestCase 

{
 @Autowired
 @Qualifier("myAppDAO")
 private IAppDao appDAO;
    ...
}

I don’t really need the line extends TestCase to run this test. It’s not needed when running this test class by itself. I had to add extends TestCase so that I can add it in a TestSuite class:

public static Test suite() {
        TestSuite suite = new TestSuite("Test for app.dao");
  //$JUnit-BEGIN$
  suite.addTestSuite(MyAppTest.class);
        ...

If I omit the extends TestCase, my Test Suite will not run. Eclipse will flag suite.addTestSuite(MyAppTest.class) as error.

How do I add a Spring 3+ test class to a Test Suite? I’m sure there’s a better way. I’ve GOOGLED and read the docs. If you don’t believe me, I’m willing to send you all my bookmarks as proof. But in any case, I would prefer a constructive answer. Thanks a lot.

  • 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-16T20:21:13+00:00Added an answer on May 16, 2026 at 8:21 pm

    You are right; JUnit4-style tests should not extend junit.framework.TestCase

    You can include a JUnit4 test as part of a JUnit3 suite this way:

    public static Test suite() {
       return new JUnit4TestAdapter(MyAppTest.class);
    }
    

    Usually you would add this method to the MyAppTest class. You could then add this test to your larger suite:

     public class AllTests {
       public static Test suite() {
         TestSuite suite = new TestSuite("AllTests");
         suite.addTest(MyAppTest.suite());
         ...
         return suite;
       }
    }
    

    You can create a JUnit4-style suite by creating a class annotated with Suite

    @RunWith(Suite.class)
    @SuiteClasses( { AccountTest.class, MyAppTest.class })
    public class SpringTests {}
    

    Note that AccountTest could be a JUnit4-style test or a JUnit3-style test.

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

Sidebar

Related Questions

No related questions found

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.