JUnit Test confusion
Hey, i had a few questions which my professor didnt really bother explaining, but when writing a JUnit test for lets say this equation (solves quadratics) i know how to test for given variable values, for e.g: p=1, q=2. But what if i wanted to test for all variable combinations of p and q?
37 Replies
⌛
This post has been reserved for your question.
Hey @mjstx! Please useTIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here./close
or theClose Post
button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
true, i was just wondering if there would be a way of doing logical checks
for all p, q variables
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
alr, like upper, lower limit and one middle value?
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
could give a short example
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
its for the plus and minus value of x
thats the mistake that the Junit test is supposed to show
task by our proff
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
alright, makes sense. What about imaginary numbers though?
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
ah mb, i meant during code execution, for the Math.sqrt, not the value iself
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
Here is your java(15.0.2) output @That_Guy977
but thats a trviial error so it doesnt count towards a mistake right?
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
basically a mistake as in something wrong with the code itself logically or syntax etc
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
alright, makes sense in this case then. Just one last thing though
in the code there a return statement but its not connected or reffering to any variable
where is the value being stored then?
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
but returned to where?
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
like for assertEquals, what would i check as my output variable?
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
quick heads up, the formula is incorrect when x1 = false
x = -(p/2) +- sqrt((p/2)² - q)
yup, theres a change in the minus sign in between the -p/2 and Math.sqr() right?
or is there something else?
no, you just need to replace the first + with a -
ah alr 👍
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
yeah but you would have to calculate the expected value first and then "see" the mistake, but here the mistake is easy to spot already
kind alike this then where you call the entire method and use it value without storing it in a variable first?
you're plugging the result of calculator.multiply(4, 5) into the 2nd argument of assertEquals, the multiply method is called first and the return value is used as 2nd argument
or, if it throws an exception, it's propagated through testMultiply and up until someone catches it or it ends up at the top of the call stack
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
alr got it chief, thanks for this i think most of my questions have been answered :GN_Dog:
If you are finished with your post, please close it.
If you are not, please ignore this message.
Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.
Post Closed
This post has been closed by <@290070433984806912>.