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

The Archive Base Latest Questions

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

For my tests I’m using a base class MyTestBase defining a method setup() that

  • 0

For my tests I’m using a base class MyTestBase defining a method setup() that does some base preparations:

public class MyTestBase {
    @Configuration( beforeTestMethod=true )
    protected void setup() {
        // do base preparations
    }
}

Now I have some more specific test classes that have to do their own preparations. There are different ways how to implement this.

I could use @Override:

public class MySpecialTestBase extends MyTestBase {
    @Override
    protected void setup() {
        super.setup();
        // do additional preparations
    }
}

…or I could use a separate setup method:

public class MySpecialTestBase extends MyTestBase {
    @Configuration( beforeTestMethod=true )
    protected void setupSpecial() {
        // do additional preparations
    }
}

Is there a prefered way to implement 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-05-12T19:10:03+00:00Added an answer on May 12, 2026 at 7:10 pm

    I would prefer using @Configuration annotation. @Override and super are more fragile. You can forget to call super.setup(), or call it in wrong place. Meanwhile, using separate method with @Configuration lets you to choose more appropriate naming for child setup method if necessary, and you get setup order guaranteed by TestNG (parent then child).

    Two more points:

    1. I’d make parent setup final in order to forbid accidental overriding.
    2. I’d use @BeforeMethod annotations. They are available since TestNG 5.0. Of course, for older versions you forced to using @Configuration.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing tests for a business method that invokes some DAO classes to perform
I'm running tests using the TestDriven.NET VS add-in, and the class library I'm testing
I ran some tests , and the data point that the jQuery inArray() is
I've ran some tests with sockets (using fsockopen() and stream_socket_client() ) and cURL to
I have some integrtion tests that create an HSQL db from JPA entities. This
I did some tests about IList<T>.Aggregate() , but the answer does not make sense
I have some unit tests (although they're Android tests, I'm using Robolectric , so
Initial tests indicate that GDI+ (writing in VB.NET) is not fast enough for my
I did some tests a while ago and never figured out how to make
I am writing unit tests for a spring mvc 3.1 application that is not

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.