Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Building a test suite in a large existing Java code base

I am working on a web application with an existing code base that has probably been around for 10 years, there are ~1000 class files and ~100,000 lines of code. The good news is that the code is organized well, business logic is separate from the controller domain, and there is a high level of reusability. The bad news is there is only the very beginnings of a test suite (JUnit); there's maybe 12 dozen tests at most.

The code is organized fairly typically for an enterprise Java project. There is a stuts-esque controller package, the model consists of almost purely data objects, there is a hibernate like database layer that is largely encapsulated within data access objects, and a handful of service packages that are simple, self contained, and logical. The end goal of building this test suite is to move towards a continuous integration development process.

  • How would you go about building a test suite for such an application?
  • What tools would you use to make the process simpler?

Any suggestions welcome. thanks!

like image 622
Peter Anthony Avatar asked Jul 15 '11 22:07

Peter Anthony


2 Answers

Start by reading Working Effectively with Legacy Code (short version here). Next I would write a couple of end-to-end smoke tests to cover the most common use cases. Here are some ideas on how to approach it: http://simpleprogrammer.com/getting-up-to-bat-series/

Then when I need to change some part of the system, I would cover it with focused unit tests (refer to the aforementioned book) and then do the change. Little by little the system - or at least the parts which change the most often - would be better covered and working with it would become easier.

like image 68
Esko Luontola Avatar answered Sep 28 '22 02:09

Esko Luontola


I would create a few integration tests. Since they toch a lot of code, you probably will get an error when you screw up bigtime.

I wouldn't 'build a testsuite' as such, but rather before changing some part define a testset for it, and then go about changing it.

I would suggest looking into a test coverage tool (I don't code Java, so no clue what tool the best is for Java). While it does not tell you when you've tested enough, it does tell you when you tested too little ;)

Good luck!

like image 38
markijbema Avatar answered Sep 28 '22 02:09

markijbema