The Artima Developer Community
Sponsored Link

Java Buzz Forum
Java News Brief (JNB): Migrating To JUnit 4

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Weiqi Gao

Posts: 1808
Nickname: weiqigao
Registered: Jun, 2003

Weiqi Gao is a Java programmer.
Java News Brief (JNB): Migrating To JUnit 4 Posted: Sep 18, 2007 4:57 PM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by Weiqi Gao.
Original Post: Java News Brief (JNB): Migrating To JUnit 4
Feed Title: Weiqi Gao's Weblog
Feed URL: http://www.weiqigao.com/blog/rss.xml
Feed Description: Sharing My Experience...
Latest Java Buzz Posts
Latest Java Buzz Posts by Weiqi Gao
Latest Posts From Weiqi Gao's Weblog

Advertisement

In the August issue of the OCI Java News Brief (JNB), Charles Sharp gave a pretty detailed prescription for migrating from JUnit 3 to JUnit 4. Besides the normal "this is what changed" material, Charles also points out some of the new features in JUnit 4.4. One of them is described thusly:

Charles Sharp: JUnit 4.4 introduces a new assert, assertThat, and some assumptions: assumeThat, assumeNotNull, assumeNoException, and assumeTrue. The 4.4 release notes give credit to Joe Walnes for the assertThat assertion mechanism. Those familiar with the jMock project will probably recognize it.

The assertThat assertions require a parameter of org.hamcrest.Matcher type. JUnit 4.4 provides several of these Matcher classes by including a third-party package, org.hamcrest.core as well as including some in the package, org.junit.matchers. According to the release notes, this is the first time a third-party package has been shipped with JUnit. A good start on using this assertion is found in a blog post by Joe Walnes, in which he explains the rationale and intended usage of assertThat.

That's something I would not have paid attention to. If you haven't figured out, I have a tendency to do the old thing. I would have been perfectly happy using JUnit 4 with just the @Before, @After and @Test annotations. Now I'm curious about this assertThat thing. And I wrote the following test:

import static org.hamcrest.core.AnyOf.anyOf;
import static org.hamcrest.core.IsSame.sameInstance;
import static org.junit.Assert.assertThat;
import org.junit.Test;

public class Foo {
    @Test()
    public void foo() {
        Object o = new Object();
        Object o1 = new Object();
        assertThat(o, anyOf(sameInstance(o), sameInstance(o1)));
    }
}

Hmmm, my unit tests can become a lot more interesting.

Got your attention? Go read the whole thing.

Read: Java News Brief (JNB): Migrating To JUnit 4

Topic: [DrunkAndRetired.om Podcast] Episode 105 - GameOnLeagues.com! from DrunkAndRetired.com Previous Topic   Next Topic Topic: Links for 2007-09-09 [del.icio.us]

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use