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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T08:54:51+00:00 2026-05-30T08:54:51+00:00

I saw this question: Repeating code in JUnit tests earlier today. How do you

  • 0

I saw this question: Repeating code in JUnit tests earlier today. How do you write this code when you are starting? You see that there is a method addDrivingRecord(...). This method does not exist when you first start writing so do you make that test, ensure that it works, then proceed with setUp() method, or do you instead wait until you have written the addDrivingRecord(...) method and then refactor it to the @Before? I will explain further if needed.

  • 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-30T08:54:52+00:00Added an answer on May 30, 2026 at 8:54 am

    If I understood well your asking if you should:

    1. use addDrivingRecord in the test method
    2. ensure it goes green (it works)
    3. refactor addDrivingRecord to @Before

    or

    1. use addDrivingRecord in the test method
    2. refactor addDrivingRecord to @Before
    3. ensure it goes green (it works)

    If it’s your question I should go for the first option: first use method, then implement and go green, then refactor your test.

    Because two reasons:

    1. You should test/implement one thing at a time, so you will write one test method. Then you will make it green. Only then you should write another method and realize that code can be refactored in a @Before

    2. A good practice is write test methods and only when you realize there are common things move them to @Before. That way you don’t enforce innecesary things in initialization. Moreover, if you find that another test needs a very different @Before method it probably belongs to another test class.

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

Sidebar

Related Questions

Is there a general difference between doing (*ptr).method() vs ptr->method() I saw this question
I saw this same question for VIM and it has been something that I
I saw this question , but the answers there are not very relevant. A
I saw this code in another question , I thought I might make it
I saw this question that asks given a string smith;rodgers;McCalne how can you produce
I saw this question asked about C# I would like an answer for PHP.
I saw this question asking about whether globals are bad . As I thought
I saw this question and it motivated me to look again (without success) at
I saw this question Inject into private, package or public field or provide a
I saw this question and it reminded me of AutoGenerateColumns in the old DataGrid.

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.