Tags » JUnit

Fun code

Although I’m not sure when it could be applicable in production to write “fun code”, I think that there is a lot of room for creativity in this area when writing tests.  261 more words

Junit

Great Expectations

What’s the best way to handle expected exceptions in JUnit?

If you want to inspect the contents of the exception and make assertions against it then there is only one clean way; Use the ExpectedException JUnit Rule. 171 more words

Clean Test Code

Why I spy

Spy is a mocking concept used to mock/stub parts of a class (“partial mocking”).
Should we use it? And if so, when?

From one perspective, gazing from an… 296 more words

Unit Test

JodaTime and JUnit

JUnit Rules are powerful things. There are all sorts of things you can do with a Rule that makes test code cleaner and less error-prone. 655 more words

Clean Test Code

Proper way to access file resources in junit tests

As I was refactoring some JUnit tests recently I was reminded of an important fact on the proper way to read in a file.
In  172 more words

Java

Parameterized unit tests in JUnit

Sometimes you may want to execute a series of tests which differ only by input values and expected results. Instead of writing each test separately, it is much better to abstract the actual tests into a single class and provide it a list of all input values and expected results. 540 more words

Java

Name_OnUnitTest_IsReadable

Naming is an important topic as its purpose is to clarify (or in the worst case obfuscate) intent. Unit tests are live documentation of the production code and therefore, I believe, must be named accordingly. 473 more words

Junit