• Post Reply Bookmark Topic Watch Topic
  • New Topic

junit results  RSS feed

 
Brian King
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I'm currently doing a problem where I alter an algorithm and then have to display various test cases.  I didn't know junit existed until yesterday and, while I think my code is ok, I don't understand how to display any results.  I just keep getting a box with what looks like a timer followed by a zero. For example, if I have the code below, how do I get it to actually show if the test case worked or not?  Do I add a print statement to each test? Do I add it to the main method somehow?

 
Stephan van Hulst
Saloon Keeper
Posts: 7932
143
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No. You need to run it in a tool that understands JUnit. Most IDE's already do this. For instance, in NetBeans you can just right-click your project and run tests. In general though, your test class name must either start or end with the word Test.
 
Junilu Lacar
Sheriff
Posts: 11435
176
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Search for information on how to run JUnit tests in the IDE you're using. In IDEs like Eclipse, Netbeans, and IntelliJ IDEA, you should see a green bar when all tests pass and a red bar if any test fails.
 
Brian King
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you happen to know what the 0 right after assertEquals( means and the 1 at the very end?  I've seen examples with an array but don't know what those two numbers stand for or are doing.



 
Junilu Lacar
Sheriff
Posts: 11435
176
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not sure why you'd ask those questions if you wrote that test code so I assume you just copied it from somewhere without understanding what it actually means. Not a good thing to do, really.

The version of the assertEquals method you used takes the expected value as its first argument and the actual value returned by the code being tested as its second argument. This means that you expect the code you're testing to have a result of 0. The 1 at the end appears to be the second parameter to the binarySearch method you're trying to test. I assume it's the value you are trying to find in the given array but you should know better than me about that.
 
Brian King
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's why I'm asking in here what it means.
 
Junilu Lacar
Sheriff
Posts: 11435
176
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are plenty of tutorials and documentation online that can give you a good introduction to JUnit. You'll get more out of this community if you ShowSomeEffort and do some legwork before asking questions you can easily find answers to yourself with a quick search. Please see my signature below for a link to our guidelines for asking questions at the Ranch.
 
Brian King
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And you can try being a little more polite instead of implying I'm cheating on something.  Maybe ShowSomeManners, dad.
 
Junilu Lacar
Sheriff
Posts: 11435
176
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I neither said nor implied anything about cheating. Copying code and trying it out is actually a valid way to learn. However, you need to understand what the code that you've copied is doing in order to learn from it. If you don't know what the code you've copied does or what the different parts mean, that's kind like getting into an airplane and expecting to be able to learn how to fly it by just punching random buttons and flipping random switches. Wouldn't it be more prudent to read the manual first? I'm not trying to be rude here; in fact, I'm trying to help you be more respectful of people who would try to help you help yourself. We're all volunteers here, we don't get paid to help you, so it's really on you to be more considerate.
 
Dave Tolls
Ranch Foreman
Posts: 3010
37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is the docs for the assertEquals being called (I suspect).
The zero is the expected value.
The second parameter is the value being tested, which seems to be the result of some other method.  What that other method is is presumably the thing under test.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!