Do most unit testers use BlueJ? I am wondering what I should learn for unit testing. Also, given that you should unit test all classes, if you are writing a class that produces a ListArray of random numbers, how in the heck to you test that?
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
Do most unit testers use BlueJ? I am wondering what I should learn for unit testing. Also, given that you should unit test all classes, if you are writing a class that produces a ListArray of random numbers, how in the heck to you test that?
I use Eclipse, but the IDE shouldn't matter. If you are comfortable with BlueJ, use it.
Mocking is an important and extremely powerful thing to learn when unit testing (google the Mockito api).
You should unit test based only on the exact expected behavior of a method. Testing whether the numbers in an array or list are random is impossible (as far as I know), since you have no "expected case" to assert with. However, if the list or array the method produces should be a certain length, you could test that. Or, you could test that all the numbers in the list or array are not the same. While this probably could happen with a random generator 0.0000000000000001% of the time, it is safe to assume all the numbers should not be the same.
Methods like the one you described are difficult to build a test case around.
EDIT: You could also run the method twice and compare the two results. If the method truly is generating a new random list every time, the values in the two lists should not be the same.
NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:
When asking for help, please follow these guidelines to receive better and more prompt help:
1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
2. Give full details of errors and provide us with as much information about the situation as possible.
3. Give us an example of what the output should look like when done correctly.
Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/
Jeff_Farkas (November 11th, 2013), Skywola (November 11th, 2013)
Thanks for the response . . . I use Eclipse for writing the code, but BlueJ for testing. BlueJ seems to be kind of cool because you can do UML in it too.