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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:04:51+00:00 2026-05-26T16:04:51+00:00

The below code is my Method logic . pulic String getData() { if (leg.length

  • 0

The below code is my Method logic .

pulic String getData()
{ 
if (leg.length == 4)
      return "ATE";
  else  if (leg.length == 2) {
      return "FTE";
      }
    if (leg.length == 3) {
      if (xr1.KotilaType.equals("CST")) {
        return "HTE";
      }
      return "DTE";
    }
   return "BTE";
  }

As ordered to me, i need to start writing Junit Test Cases for this Method.

As you can see there is only One method and a number of conditions inside this method .

Now my question is ,
Do we need to write a Seperate Junit TestCase ( A Seperate Method) for each condition ??

Or will it be sufficient to write only One Junit TestCase and cover all the above conditions ??

I am new to junit and not a expert , please guide me what is the approiate way for writing JunitTestCases for the above method ??

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

    This is question of style. These are the two alternatives: With all in one method:

    public void testAll() {
        assertEquals("ATE", getData(leg4));
        assertEquals("FTE", getData(leg2));
        // etc.
    }
    

    With one test method / combination:

    public void testLength4() {
        assertEquals("ATE", getData(leg4));
    }
    
    public void testLength2() {
        assertEquals("FTE", getData(leg2));
    }
    

    The former has the advantage that it is very easy to see all combinations, because they’re all in one place. This is very useful if there are a lot of combinations or the combinations are complex.

    The latter has the advantage that you have one test per combination, so it’s very easy to localize a problem, because (theoretically) only one test will fail. Disadvantage: you very quickly run out of names for test methods. testLength4, testLength2, testLength3WithCST, testLength3WithoutCST. This disadvantage gets particularly bad when you have a lot of combinations (say like one test for each month in a year).

    Most of the time, I use one test method / test case, but if the number of combinations starts to get high, I would have a single method. This contains all of the combinations, because I like to be able to see all of my combinations at once, to see if I’ve missed any.

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

Sidebar

Related Questions

I use the below code to write code to query a web method in
The code below generates a warning CS3006 Overloaded method MyNamespace.Sample.MyMethod(int[])' differing only in ref
In the code below I pass method B as an action to be perfomed
Consider the Java code below, what would happen if there were no paintComponent method
Edit Based on suggestions below to send the logic code GUI delegates, I came
Below code saying error incorreect syntax near Main INSERT INTO tbl ( 'Week', Main,
The below code is very simple. I have a jQuery autocomplete bound to an
My below code works fine and is used to populate a <select> item with
The below code works when there are a few element in the To list
The below code in Java throws Null pointer exception. public class New{ int i;

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.