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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T05:32:51+00:00 2026-06-09T05:32:51+00:00

We have lots of selenium tests running through junit, and they all have a

  • 0

We have lots of selenium tests running through junit, and they all have a few steps which need to run before the actual tests. For this we have a parent TestCase class which has some @Before and @After methods in it.

Now, due to a new feature of our site I would like to parameterise part of this set up, I’d like to create a new annotation to put on some tests to indicate to the setup() method that the setup is slightly different, whilst allowing the others to use the default. So, is it possible to reflectively access the test method about to be run in an @Before method?

eg.

class SomeTest extends MyTestCase {

  @Test
  @Flavour(Red.class)
  public void testRedFlavouredHomepage() {
    testHomepage();
  }

  @Test
  public void testBlueFlavouredHomepage() {  // assuming Blue is my default flavour
    testHomepage();
  } 

  public void testHomepage() {
    // test some stuff
  }
}
  • 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-09T05:32:53+00:00Added an answer on June 9, 2026 at 5:32 am

    You can do this using @Rule (with the later versions of JUnit >= 4.9). If you have a class which implements TestRule, specifically apply(), you can do extra things before your test gets run. The Description is passed to the apply method, which contains the annotations on your method:

    Using @Deprecated as an example:

    public class ExtraSetupTest {
      @Rule
      public TestRule moreSetup = new TestRule() {
        public Statement apply(Statement base, Description description) {
          return statement(base, description);
        }
    
        private Statement statement(final Statement base,
            final Description description) {
          return new Statement() {
            @Override
            public void evaluate() throws Throwable {
              if (description.getAnnotation(Deprecated.class) != null) {
                System.out.println("more setup here");
              }
              base.evaluate();
            }
          };
        }
      };
    
      @Test
      public void noExtraSetup() {
        System.out.println("noExtraSetup");
      }
    
      @Test
      @Deprecated
      public void withExtraSetup() {
        System.out.println("withExtraSetup");
      }
    }
    

    This produces as output:

    noExtraSetup
    more setup here
    withExtraSetup
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have lots of stored procedures which all contain a lot of comments. Is
I have seen lots of questions and solutions on File upload using Selenium WebDriver
I have LOTS of logs and I need to compress them in a weekly
I have lots and lots of C preprocessor #define statements, which make my C
I have lots of bson files in the following path: c:/mongodb/bin/dump/Sid If I run
I have lots of jobs in my system that are long-running but not CPU
I have lots of transparent primitives I want to sort before drawing, but to
i have lots of data like this 1:0x00a4c7d9fb3849... 2:0x79821309bd789c7689c97... 3:0x0178dce67fe898... they are more than
I have lots of text marked up like this: <span class=section>[<a href=blablabla>Section</a>]</span> I need
I have lots of variables in R, all of type list a100 = list()

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.