I need good examples of Junit tests for Java classes, to spend in training, anyone have suggestions of good examples?
4 Answers
Here is a good one which shows you step by step what you have to do, including screenshots with Eclipse also.

- 9,603
- 14
- 91
- 162
-
If it fits your needs you should mark it as answer. Thanks. – Cristian Boariu Apr 16 '11 at 14:03
-
@C. Boariu: Do not ask to quick for your reputation points. This is a very general question and you should give both sites the possibility to give and find the best answer. – FrVaBe Apr 18 '11 at 10:06
-
@K. Claszen Yeah, I know what you mean. But I asked this because a lot of the new comers on stackoverflow does not use "Mark As Answer" option but leave the question after they find an answer... – Cristian Boariu Apr 18 '11 at 10:10
JUnit tests are somehow based on your procedures. It depends what do you want to test. For example, if you want to test if for specific input, you receive specific output, you can use assertEquals. For writing a simple step by step JUnit test in Java in Eclipse, look at "Write Simple JUnit Test".
For thorough information, look at "Unit Test Tutorials".
From memory, I think Kent Beck's Test Driven Development walks through some good examples. Probably a good book to refer to in testing training courses. http://www.amazon.co.uk/Test-Driven-Development-Addison-Wesley-Signature/dp/0321146530

- 44,585
- 16
- 110
- 102
-
Adrian I to Think in this book, but in this time a looking for a resource in the web. Thanks. – Édipo Féderle Apr 16 '11 at 13:52
You can have a look at open source software - maybe a library which you use for yourself. They often contain unit tests, e.g.:
I do not know what you mean with 'to spend in training' but if you will use it for other purpose than to train yourself check the license first.

- 47,963
- 16
- 124
- 157
-
-
@Sarz Thanks for letting me know. Guava moved to GutHub - I updated the link. – FrVaBe Dec 12 '14 at 15:29