englishteeth.co.uk

… the weblog of Ian “English Teeth” Robinson
  • rss
  • Home

JUnit 4

Ian | March 11, 2008

Not least because it is so much simpler, but regular usage will result in this will becoming ingrained, (this is covered in greater detail here), but being as I’m so used to the previous incarnations of JUnit it might be worth noting the usage for quick look-up…

package junit4;

import mypackage.ClassToTest;
import org.junit.Before;
import org.junit.After;
import org.junit.Ignore;
import org.junit.Test;
import static org.junit.Assert.*;

public class MyJUnit4Test {

  private static ClassToTest classToTest = new ClassToTest();

  @Before
  public void whatUsedToBeInSetup() {
    // test set up type activities
  }

  @Test
  public void first() {
    classToTest.doWhatYouDo();
    assertEquals(classToTest.getWhatItDid(), result);
  }

  @Test(expected = SomeParticularException.class)
  public void shouldCauseExceptionInTestClass() {
    classToTest.doThatThingYouDontLike();
  }

  @Ignore("not ready yet")
  @Test
  public void multiply() {
    classToTest.doThatThingYouWillDo();
    assertEquals(classToTest.getWhatItDid(), futureResult);
  }

  @After
  public void whatUsedToBeIntearDown() {
    // test tear down type activities
  }

}

Minor Eclipse Annoyance - organise imports changes import static org.junit.Assert.* to whatever asserts you’ve actually referenced. This being an annoying when you’re developing iteratively and may not yet have used all the asserts you might wish to use.

Categories
development, software
Tags
java, junit, testing
Comments rss
Comments rss
Trackback
Trackback

« Bauhaus: Resurrection or Resuscitation HD Playback Configuration »

Leave a comment

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

Author

Ian Robinson is a relatively agile software engineer interested in things both sides of the object relational divide and beyond.

Categories

  • development (37)
  • miscellaneous (28)
  • music (7)
  • software (19)

What I'm Doing...

  • @noelfielding11 why are you in watching telly!? in reply to noelfielding11 2010-04-16
  • What was so good about Nick Drake? These "artists" are covering, music is spot on but no effect at all. Totally lacking the goose pimples. 2010-04-16
  • Some Ginger bloke's on telly covering Nick Drake in a mediocre style. 2010-04-16
  • More updates...

Posting tweet...

Powered by Twitter Tools.

Blogroll

  • Dan North
  • Dave Astels
  • Dave Wood
  • eirikso.com
  • Matt Raible
  • Object Mentor Blog
  • The Ancient Art of Programming
  • The Wisdom of Ganesh

Tags

active-mq architecture bauhaus css db eclipse esb festivals freesat gorm grails groovy hd hibernate htpc java jboss jms junit links mce media center mini music oracle osgi patterns pirsig plugins satellite soa software spring sql struts2 testing themes tools tv vmc web wordpress xml xpath xslt
rss Comments rss valid xhtml 1.1 design by jide powered by Wordpress get firefox