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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:27:26+00:00 2026-06-11T16:27:26+00:00

I have two tests they are exactly the same… barring two things, they call

  • 0

I have two tests they are exactly the same… barring two things, they call two separate service calls.. hence when im using mockito i have two seperate expectation and verify lines…

this is what i have done:

@test
TestA {
   baseTest("player");
}

@test
TestB {
  baseTest("member");

}

BaseTest(type type) {
  ....
  .....
  if type(player) {
    Mockito.when(player service call)
  }
  else {
    Mockito.when(member service call)
  }

  // make the call in code

  //verify

  if(player) {
     verify player specific service call...
  }
  else {

  }
}

I think the above is a test smell… just doesnt feel right…

Is there a better way then placing an If statement in my baste test?

  • 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-11T16:27:28+00:00Added an answer on June 11, 2026 at 4:27 pm

    You should develope your test code independenly and join things when they have sense.

    By example. One rule of thumb for initialization code (the first A of Arrange/Act/Assert) is that:

    1. you should write all the Arrange part of a test method in the test.
    2. if your method shares initialization with all the other methods, then put it in a @Setup method
    3. if some test method doesn’t share that initialization it’s probably because it doesn’t fit in that test case.

    So my conclusion is:

    1. write independent tests
    2. if they share things you can refactor
    3. but not too much (or in a weird thing like “if”s)!!! Adds complexity, not reuse.

    In fact @artbristol answer makes sense: if you are using if’s for alternate behaviour consider polymorphism. It’s just I’m not sure until which point it’s complex for test or not (probable it makes sense if the code is testing a similar class hierarchy).

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

Sidebar

Related Questions

I have these two tests. They pretty much do the same thing, so I
I have two tests to check the expected exception throw. I am using Junit
I have two folders, f1 and f2, and they are on same level (have
I have two PHP functions to calculate the relation between two texts. They both
Currently I have two tests that each individually test for a button_click within a
I have two unit tests that should share a lot of common tests with
I have two Controller unit tests and each one sets an HttpClient metaclass execute
I have written two short tests and compiled both with g++ -S (gcc version
I have two projects: a profiler and a basic application (with JUnit tests) The
Let's say I have two maven profiles for running projects web tests: 1. first

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.