JaVa
   

Summary

Important 

Testing should occur throughout the software lifecycle. Testing should be a core activity of software development.

Test cases should usually be written before code. Instead of considering app code as the sole deliverable, test cases, documentation (Javadoc and other), and app code should be kept in sync, with the test cases being written first. If you can't write a test for a piece of code, you don't know enough to write the code itself. A test that isn't up-to-date is useless. Unless tests are easy to run, they won't be run. It's vital that unit tests can be run automatically, and that there is no need to interpret the results - there should be a single indication of success or failure. Ant can be used to automate tests written with JUnit. It's important to invest a little time early in the project lifecycle in establishing testing conventions and streamlining the testing process so that all developers can efficiently write and execute tests. Especially in the case of web apps, stress testing is vital. Unsatisfactory performance is a serious risk in enterprise software development, and should be tackled early, through a proof of concept, while it isn't prohibitively expensive to modify the app's design. Testing J2EE apps involves many different tests. We've considered the following test strategies:

We've also discussed the desirability of designing apps so that central functionality can be tested against ordinary Java classes, rather than harder-to-test J2EE components. Testing alone is not enough to ensure that code is bug free. Other useful strategies include using assertions in app code and introducing the practice of regular code reviews. Sound coding and design practices can do much to reduce the likelihood of bugs.

While the concepts discussed in this chapter apply whatever tools we use, I've concentrated on free, simple tools. These are ubiquitous and widely understood, but there are more sophisticated commercial testing tools available, especially for web apps, that are beyond the scope of this chapter.

JaVa
   
Comments