UnitTest for int function failed
I'm trying to create a unit test for simple class that contain function which return number and this is the function:
public static int Result(){
// code of function here it return value equal to 99
return output;
}
and this is my main method where I call this method and print it's result:
public static void main(String args) {
System.out.println("result is= " + Result());
}
and when I run the program the output that I get in run is 99
now in my test class this is my test code for Result() function:
@Test
public void testResult() {
System.out.println("Result");
int expResult = 99;
int result = javaClass.Result();
assertEquals(expResult, result);
}
and this is the other code nad methods of test class:
JavaTask javaTask;
public JavaTaskTest() {
}
@Before
public void setUp() {
javaTask = new JavaTask();
}
@After
public void tearDown() {
javaTask = null;
}
When I run the test I got this error:
testResult Failed: expected <99> but was <200>
why I got the result from the JavaClass different in test class than the result that really returned by same function in JavaClass when I run it
java unit-testing
|
show 1 more comment
I'm trying to create a unit test for simple class that contain function which return number and this is the function:
public static int Result(){
// code of function here it return value equal to 99
return output;
}
and this is my main method where I call this method and print it's result:
public static void main(String args) {
System.out.println("result is= " + Result());
}
and when I run the program the output that I get in run is 99
now in my test class this is my test code for Result() function:
@Test
public void testResult() {
System.out.println("Result");
int expResult = 99;
int result = javaClass.Result();
assertEquals(expResult, result);
}
and this is the other code nad methods of test class:
JavaTask javaTask;
public JavaTaskTest() {
}
@Before
public void setUp() {
javaTask = new JavaTask();
}
@After
public void tearDown() {
javaTask = null;
}
When I run the test I got this error:
testResult Failed: expected <99> but was <200>
why I got the result from the JavaClass different in test class than the result that really returned by same function in JavaClass when I run it
java unit-testing
2
Post a Minimal, Complete, and Verifiable example...
– Reimeus
Dec 27 '18 at 22:02
@Reimeus you can just expect output = 99 and test code you don't need a long code that contain many functions which all of them lead to the final result while the problem is not with code it self but with testing : /
– GNDevs
Dec 27 '18 at 22:07
Delete all the code in the Result method and replace it with: return 100; then what happens when you run your test?
– WW.
Dec 27 '18 at 22:29
okay when delete all code of Result method and make it just return 99 then went to my test and run it and the test is just passed!!! but when I use System.out.println(output); in the Result function it print the 99 so why it chanced to another number in test class ? @WW.
– GNDevs
Dec 27 '18 at 22:41
The answer to your question is in the code you didn't show us. Perhaps you are calling different code to what you think you are. JavaTask vs javaClass
– WW.
Dec 28 '18 at 7:11
|
show 1 more comment
I'm trying to create a unit test for simple class that contain function which return number and this is the function:
public static int Result(){
// code of function here it return value equal to 99
return output;
}
and this is my main method where I call this method and print it's result:
public static void main(String args) {
System.out.println("result is= " + Result());
}
and when I run the program the output that I get in run is 99
now in my test class this is my test code for Result() function:
@Test
public void testResult() {
System.out.println("Result");
int expResult = 99;
int result = javaClass.Result();
assertEquals(expResult, result);
}
and this is the other code nad methods of test class:
JavaTask javaTask;
public JavaTaskTest() {
}
@Before
public void setUp() {
javaTask = new JavaTask();
}
@After
public void tearDown() {
javaTask = null;
}
When I run the test I got this error:
testResult Failed: expected <99> but was <200>
why I got the result from the JavaClass different in test class than the result that really returned by same function in JavaClass when I run it
java unit-testing
I'm trying to create a unit test for simple class that contain function which return number and this is the function:
public static int Result(){
// code of function here it return value equal to 99
return output;
}
and this is my main method where I call this method and print it's result:
public static void main(String args) {
System.out.println("result is= " + Result());
}
and when I run the program the output that I get in run is 99
now in my test class this is my test code for Result() function:
@Test
public void testResult() {
System.out.println("Result");
int expResult = 99;
int result = javaClass.Result();
assertEquals(expResult, result);
}
and this is the other code nad methods of test class:
JavaTask javaTask;
public JavaTaskTest() {
}
@Before
public void setUp() {
javaTask = new JavaTask();
}
@After
public void tearDown() {
javaTask = null;
}
When I run the test I got this error:
testResult Failed: expected <99> but was <200>
why I got the result from the JavaClass different in test class than the result that really returned by same function in JavaClass when I run it
java unit-testing
java unit-testing
asked Dec 27 '18 at 21:57
GNDevs
15810
15810
2
Post a Minimal, Complete, and Verifiable example...
– Reimeus
Dec 27 '18 at 22:02
@Reimeus you can just expect output = 99 and test code you don't need a long code that contain many functions which all of them lead to the final result while the problem is not with code it self but with testing : /
– GNDevs
Dec 27 '18 at 22:07
Delete all the code in the Result method and replace it with: return 100; then what happens when you run your test?
– WW.
Dec 27 '18 at 22:29
okay when delete all code of Result method and make it just return 99 then went to my test and run it and the test is just passed!!! but when I use System.out.println(output); in the Result function it print the 99 so why it chanced to another number in test class ? @WW.
– GNDevs
Dec 27 '18 at 22:41
The answer to your question is in the code you didn't show us. Perhaps you are calling different code to what you think you are. JavaTask vs javaClass
– WW.
Dec 28 '18 at 7:11
|
show 1 more comment
2
Post a Minimal, Complete, and Verifiable example...
– Reimeus
Dec 27 '18 at 22:02
@Reimeus you can just expect output = 99 and test code you don't need a long code that contain many functions which all of them lead to the final result while the problem is not with code it self but with testing : /
– GNDevs
Dec 27 '18 at 22:07
Delete all the code in the Result method and replace it with: return 100; then what happens when you run your test?
– WW.
Dec 27 '18 at 22:29
okay when delete all code of Result method and make it just return 99 then went to my test and run it and the test is just passed!!! but when I use System.out.println(output); in the Result function it print the 99 so why it chanced to another number in test class ? @WW.
– GNDevs
Dec 27 '18 at 22:41
The answer to your question is in the code you didn't show us. Perhaps you are calling different code to what you think you are. JavaTask vs javaClass
– WW.
Dec 28 '18 at 7:11
2
2
Post a Minimal, Complete, and Verifiable example...
– Reimeus
Dec 27 '18 at 22:02
Post a Minimal, Complete, and Verifiable example...
– Reimeus
Dec 27 '18 at 22:02
@Reimeus you can just expect output = 99 and test code you don't need a long code that contain many functions which all of them lead to the final result while the problem is not with code it self but with testing : /
– GNDevs
Dec 27 '18 at 22:07
@Reimeus you can just expect output = 99 and test code you don't need a long code that contain many functions which all of them lead to the final result while the problem is not with code it self but with testing : /
– GNDevs
Dec 27 '18 at 22:07
Delete all the code in the Result method and replace it with: return 100; then what happens when you run your test?
– WW.
Dec 27 '18 at 22:29
Delete all the code in the Result method and replace it with: return 100; then what happens when you run your test?
– WW.
Dec 27 '18 at 22:29
okay when delete all code of Result method and make it just return 99 then went to my test and run it and the test is just passed!!! but when I use System.out.println(output); in the Result function it print the 99 so why it chanced to another number in test class ? @WW.
– GNDevs
Dec 27 '18 at 22:41
okay when delete all code of Result method and make it just return 99 then went to my test and run it and the test is just passed!!! but when I use System.out.println(output); in the Result function it print the 99 so why it chanced to another number in test class ? @WW.
– GNDevs
Dec 27 '18 at 22:41
The answer to your question is in the code you didn't show us. Perhaps you are calling different code to what you think you are. JavaTask vs javaClass
– WW.
Dec 28 '18 at 7:11
The answer to your question is in the code you didn't show us. Perhaps you are calling different code to what you think you are. JavaTask vs javaClass
– WW.
Dec 28 '18 at 7:11
|
show 1 more comment
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53951267%2funittest-for-int-function-failed%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53951267%2funittest-for-int-function-failed%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
Post a Minimal, Complete, and Verifiable example...
– Reimeus
Dec 27 '18 at 22:02
@Reimeus you can just expect output = 99 and test code you don't need a long code that contain many functions which all of them lead to the final result while the problem is not with code it self but with testing : /
– GNDevs
Dec 27 '18 at 22:07
Delete all the code in the Result method and replace it with: return 100; then what happens when you run your test?
– WW.
Dec 27 '18 at 22:29
okay when delete all code of Result method and make it just return 99 then went to my test and run it and the test is just passed!!! but when I use System.out.println(output); in the Result function it print the 99 so why it chanced to another number in test class ? @WW.
– GNDevs
Dec 27 '18 at 22:41
The answer to your question is in the code you didn't show us. Perhaps you are calling different code to what you think you are. JavaTask vs javaClass
– WW.
Dec 28 '18 at 7:11