Stories, software, and a life lived across several worlds
Fixing defects at a late stage in a project is more costly and causes more pain than doing it as early as possible.
Testable code is good code. Testing is essential to agile processes. AOP helps to isolate concerns. Infrastructure can be left out of the business logic and hence makes testing the business logic easier or - in some cases - possible.
Developers should take ownership of unit and integration tests and not rely on a QA function. A QA function is still needed, but developers should start testing while writing code. Many developers don't test the UI, which is bad. JWebUnit can help with that for web applications.
Rod stresses the importance of performance assurance and regression testing. The Grinder is a free tool for load testing.
Unit testing. Don't use Spring in a unit test. Do use mocks or stubs. Unit tests should run extremely fast. With mock objects you can create expectations. See Easymock or Mockobjects. Mock objects are great for service layer objects and domain objects and to test what happens in the event of a failure. A few things that make testing hard: static methods, final classes. You can't test in isolation: configuration, JDBC code or O/M mapping and how classes work together.
Artifacts to test: service layer, domain objects, special cases such as aspects, web tier code, code containing SQL or other queries and code interacting with J2EE APIs. Non-Java code like stored procedures or triggers, database schema and views. O/R mappings, Spring configuration, JSPs and other view technologies. With Velocity you can test the without being tied to a container.
In-Container testing with tools like Cactus is not the answer.
Spring helps with the org.springframework.test package available in spring-mock.jar since Spring 1.1.1. Provides Spring context loading and caching, transaction management and - of course - dependency injection.
Put things like the datasource and transaction manager declaration in configuration files of their own so you can use different ones for testing and production use.
If you are on Java5 use AbstractAnnotationAwareTransactionalTests for tests.
Use the JDBCTemplate exposed by the abstract classes to verify that the O/RM tool did what it's supposed to do.
Test lazy loading with endTransaction()
startNewTransaction() to test attach/detach in an ORM tool (merge() or saveOrUpdate()). Test locking strategies.
| Previous | 09 Dec 2006 | Next |
About me
Hello! My name is Stephan Schwab.
I build and rescue software, and I write fiction about the human side of how it gets made. Here you’ll find my stories and novelas, notes on craft, and field notes from a life lived across several worlds.
Working with software teams is what I do professionally — see how on caimito.net. You can also read about my experience since 1986.
Work with me
Hire me as the senior who embeds in your team and makes it ship.
Stories & writing
On the craft
Life across several worlds
Places that shaped me
Open Source
Stay in touch
LinkedIn Mastodon Bluesky TikTok Twitter RSS Email
Everything
See a listing of all posts on this site.