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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:12:03+00:00 2026-05-26T12:12:03+00:00

I would like my @Before method to know the currently executing tests Annotations, so

  • 0

I would like my @Before method to know the currently executing tests Annotations, so that the @Before method can do various things. Specifically, right now our @Before always does various initialization steps like reloading the database, etc. I would like to be able to write code like this:

@Before
void setUp() {
    if (testMethod.hasAnnotation(@NeedsDatabase)) {
        reloadDatabase();
    }
}

I guess one solution would be to use a @Rule for DB initialization, but this would be complicated to implement and our existing infrastructure already handles this in @setUp. We already have a custom Runner and all tests extend a shared base class, if that helps.

I tried to think of a way to do this, but I don’t know what is available in JUnit4.

  • 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-26T12:12:04+00:00Added an answer on May 26, 2026 at 12:12 pm

    You could use the @RunWith annotion, and create your own ParentRunner that scans for your @NeedsDatabase annotation and handles setup appropriately.

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

Sidebar

Related Questions

I would like to produce an executable that could make an update verification before
I would like to check which type of RAM my computer uses before I
I would like to be able to manipulate the DOM just before my page
I would like to modify the string in a .h file with NAnt before
I would like to get text width of a string before an application starts.
Basically I would like to tell MSTest to execute a bit of code before
I would like to select a cell in a tableview, except with code before
Before trying to query the AD server I would like to check if it
While related questions have been asked before I would like to see an idea
For my web-application I would like to add an object before another object inside

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.