«« jid3rL Wrapped in SimpleTag2 id3v2 Frame Gigantism »»
blog header image
Automatic Object Test Generation

Something that's becoming apparent after working on jid3rL is that it's nice to have well tested objects but it's a pain to test them. If you start from the bottom with very well tested objects, then you'll have less defects when you integrate them together and use them with other code.

The problem is actually testing them, making them bulletproof. The equals() and hashCode() methods have very specific "contract" conditions that are easy to test. But writing the tests is tedious, especially for simple immutable objects like the ones I use in jid3rL.

It would be nice if I could generate these tests automatically and save a lot of work. It could be an Eclipse plugin ...

You mark the member variables that you want to count when determining object equality for that class, and then the tests are generated automatically. It could generate far more tests than you would normal do manyally, since it wouldn't take long to regenerate them again if you added a new member variable.

Speaking of that, if you did add a new member variable the Eclipse plugin could pop up an error/warning in the Problems view telling you to regenerate the tests again.

Posted at August 17, 2004 at 11:38 PM EST
Last updated August 17, 2004 at 11:38 PM EST
Comments

Why stop at having the plugin generate the tests? Why not have the plugin generate the equals, hashcode, toString, and (optionally) the compareTo methods as well? They are all pretty tedious and follow simple, established rules.

That's something that I would much rather the IDE did for me and saved me the time so that I can solve the problem that I was hired to do.

» Posted by: Jim at August 18, 2004 08:15 AM

I was just thinking that this morning actually. For simple classes that generate immutable objects it would be relatively easy to map out the implementation as well. All of the members are private final, and the only have getter methods.

What would be nice is a New Immutable Object wizard that generates an immutable object given a list of member variables (and their types), and optionally an accompanying test class.

» Posted by: Ryan at August 18, 2004 08:46 AM

Again, why stop there?

Why would you want to restrict this "cool" feature to just immutable objects? Why not extend it to other objects? This is (sort of) where I was going when I was making the reflexive object methods (for simple ActionForm classes). This is definally something that would be great for any entity objects.

http://www.beernut.ca/jim/archives/001763.html

» Posted by: Jim at August 18, 2004 09:55 AM

I have a big gut feeling that the piece of software you guys speaking off already exists somewhere, or is right in front of our faces.

» Posted by: Jimmy at August 18, 2004 10:06 AM

Well Rational Rose/XDE will generate code based on a UML model. It won't generate tests though.

I'm also not sure how closely Rose/XDE watches the code to make sure you don't break the tests. I'm pretty sure XDE integrates into Eclipse, but I don't know if it reads the code after it generates it and updates the model it has, or is just one way.

» Posted by: Ryan at August 18, 2004 11:03 AM
Google
 
Search scope: Web ryanlowe.ca