views:

115

answers:

4

I noticed some unit tests, like in the spring framework where you setup the object and the test but don't explicitly use the assert methods.

Essentially, you have an exception or not.

Is this unit testing? Is this something to avoid? For example, here are some tests from the Spring framework. No assert clauses, just a test.

public void testNeedsJoinPoint() {
 mockCollaborator.needsJoinPoint("getAge");
 mockControl.replay();
 testBeanProxy.getAge();
 mockControl.verify();
}
+4  A: 

The test you are showing is full of expectations, but they are expressed in terms of the mock object.

Some tests may be totally void of asserts and still be ok with me, for instance a test that simply loads the spring context and (implicitly) asserts its validity. I really think the question should be if it is a good test. Sometimes it may be, and sometimes it's just the best you can get. And it may often be a lot better than nothing.

krosenvold
+1  A: 

Every exception let the test fail. So you can use your own exceptions to break your Unit test.
If you read the source code, a assertXXX will throw an Exception to the TestRunner. So Unit tests are build upon exceptions.

Mocking is definitely nothing to avoid. It's good, because it may encourage isolation of your tests.

furtelwart
A: 

I call this "smoke testing" and do it very often.

It is like running your engine and assert that there is no smoke, ie no exceptions are thrown. Personally, I consider this good style (but hey, I am also the guy that promotes dependent test :)

Adrian
A: 

If you're concerned, try breaking the code to make sure that the tests are effective.

Steve Freeman