The first test method

Published by Rob on October 4th, 2004 - in Java

When writing a class that will slot into a framework, I often know that I will need it to implement an interface. The quickest way of getting a test writen is to do this:

1
2
3
public void testSaveActionIsAnAbstractAction() throws Exception {
    assertTrue(AbstractAction.class.isAssignableFrom(SaveAction.class));
}

I then don’t need to type any of this…..

public class ISMSaveAction extends AbstractAction{
public void actionPerformed(ActionEvent e) {
throw new NoSuchMethodError();
}
}

and my next test is obvious.

This test is not to replace the tests that actually test real behaviour. It is a nice way to start getting your code writen, and helps keep the flow of red/green/refactor going.

Related posts:

  1. Technique for getting JUnit tests to compile
  2. Fun with Ant FileScanners… or FIT Test harness
  3. Tuning tests…. fun for all the family
  4. FemtoContainer
  5. Writing Test Driven Swing ñ my plan

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

© Rob@Rojotek