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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T17:52:53+00:00 2026-06-11T17:52:53+00:00

I have large number of test cases which runs with Spring Junit Support with

  • 0

I have large number of test cases which runs with Spring Junit Support with following annotations on each Test.

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations="classpath:spring/applicationContext.xml")
@TransactionConfiguration(transactionManager="transactionManager")
@Transactional
@ActiveProfiles("test")

Instead of putting all these annotations on each Test class I want to Create a Custom Annotation and use it.

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations="classpath:spring/applicationContext.xml")
@TransactionConfiguration(transactionManager="transactionManager")
@Transactional
@ActiveProfiles("test")

@Target({ ElementType.FIELD, ElementType.PARAMETER, ElementType.TYPE })
@Retention(RetentionPolicy.RUNTIME)
@Inherited
public @interface SpringJUnit4TestConfig {

}

But when I use this Custom Annotation Spring Injection is not happening at all.

@SpringJUnit4TestConfig
public class UserServiceTest
{
}

What I am missing here?

PS:
But JUnit’s @RunWith and Spring’s @Transactional, @ContextConfiguration all have @Inherited..So I thought it should work. But for now I get through it through a work around. Created a Based Abstract class and put all those Annotations on it and the test cases extending that Base class.

  • 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-11T17:52:55+00:00Added an answer on June 11, 2026 at 5:52 pm

    I don’t think that this approach will work, as @RunWith is JUnit annotation, so for this to work JUnit annotations must be transitive.

    When a class is annotated with @RunWith or extends a class annotated with @RunWith, JUnit will invoke the class it references to run the tests in that class instead of the runner built into JUnit. We added this feature late in development. While it seems powerful we expect the runner API to change as we learn how people really use it. Some of the classes that are currently internal will likely be refined and become public.

    So test JUnit test invoking seem to work only for the inherited classes.

    As for Spring, it supports a thing called context configuration inheritance for configuration locations, I’m quite not sure that this should work for other annotations types (please point me to the documentation, if you think otherwise) Actually, this will likely work for other annotations in case of test configuration class inheritance because @Transactional annotation itself is declared with @Inherited for this case.

    So in this case, it does not run because of JUnit annotation’s missing.

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

Sidebar

Related Questions

I have a large number of objects which are identified by names (strings). So,
I have a large number of data points which are two dimensional coordinates with
I have a large number of text files (1000+) each containing an article from
I have a large number of test set-up through a StaticTestFactory, but when I
I have a large number of records (10,000, increasing every day) that essentially is
I have a large number of documents (mainly PDFs) that I want to index
I have a large number of csv files that look like this below: xxxxxxxx
I have a large number of instances of a C structure like this: struct
We have a large number of programmers on different platforms all using CVS. We
I have a large number of C# WCF services that are being called by

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.