473,382 Members | 1,743 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

How to test local variable in method using junit test case?

Hi friends,

Being new in junit i have onw question that How to test local variable in method using junit test case?
Check that below is my method suppose,

Expand|Select|Wrap|Line Numbers
  1. public void methodToCheckStr(int testVar)
  2.     {
  3.         String str="";
  4.         if(testVar==5)
  5.         {
  6.             str="Success";
  7.         }
  8.         else
  9.         {
  10.             str="fail";
  11.         }
  12.     }
  13.  
How to create test case to check what is 'str' contains?

Kindly help me out here.
May 10 '17 #1

✓ answered by chaarmann

You can't.
If it would be a field instead a local variable, you could test it via reflection.

But anyway, the method can return "str" as a value and then you can test against that value.

That means in JUnit you are only testing the result of public methods.

1 10618
chaarmann
785 Expert 512MB
You can't.
If it would be a field instead a local variable, you could test it via reflection.

But anyway, the method can return "str" as a value and then you can test against that value.

That means in JUnit you are only testing the result of public methods.
May 15 '17 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Kench | last post by:
I was curious and playing with pointers and references to see what's different between them. Other than the obvious ones involving C++ syntax & things like references cannot be modified with...
18
by: Joe | last post by:
Hi, I am trying to alter the refresh rate of an online webpage in a webbrowser control using MFC. However the Timer ID is stored in a local variable and I don't know how to access it. Is there a...
9
by: tshad | last post by:
I am getting an error: Use of unassigned local variable 'postDateRow' But it is assigned. Here is the code: int payDateRow; int postDateRow;
2
by: silversurfer | last post by:
Hello, I am a little unsure whether this method really makes sense. The goal is to add an element to a vector. This is the struct and method I am using: std::vector<Entry> models; struct...
4
by: rsa_net_newbie | last post by:
Hi there, I have a Managed C++ object (in a DLL) which has a method that is defined like ... Generic::List<String^>^ buildList(String^ inParm) Now, when I compile it, I get "warning C4172:...
6
by: yasodhai | last post by:
Hi, I used a dropdown control which is binded to a datagrid control. I passed the values to the dropdownlist from the database using a function as follows in the aspx itself. <asp:DropDownList...
8
by: Dom | last post by:
This is a little tricky, but I think the error I'm getting isn't valid. The compiler just doesn't know my logic. MyObject o; switch (IntVariable) { case 1: o = new MyObject() break;
2
by: Wang, Harry | last post by:
$$ TestCase ID : 001 Step : deleteDvc,206268 Result Eval type : XmlChk Step : deleteDvc,206269 Result Eval type : XmlChk Traceback (most recent call last): File "C:\UDR2\UDRxmlGateway.py", line...
6
by: =?Utf-8?B?bGlhbnF0bGl0?= | last post by:
lets say there are 3 int ncount variable in every method private void x_method1() { int ncount = dv.length; } private void x_method2() { int ncount = drarr.length;
4
by: Stephen Cattaneo | last post by:
Hello all, I am attempting to execute an automated test (written in Python) via cron. I have to check the HOSTNAME variable as part of the test, oddly under cron the HOSTNAME environment...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.