Tags » JUnit

Note: Pragmatic Unit Testing in Java 8 with JUnit

I read the first version when I was in college. It introduced TDD and Junit to me just fine. I’d like to read the latest version to refresh my memory. 681 more words

My Reading

JUnit test TestGoogleGeocoding

package test.nl.kameroom.location;

import java.io.InputStream;
import java.io.StringReader;
import java.net.URI;
import java.net.URL;
import java.sql.SQLException;

import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathFactory;

import org.apache.commons.io.IOUtils;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.xml.sax.InputSource;

public class TestGoogleGeocoding {
	public static void setUpBeforeClass() throws Exception {

	public static void tearDownAfterClass() throws Exception {

	public void setUp() throws Exception {

	public void tearDown() throws Exception {

	public void testGeocoding() throws Exception {			
		URI uri = new URI(
		URL url = uri.toURL();
		InputStream is = url.openStream();
		String xml = IOUtils.toString(is, "utf-8"); //encoding is important
		XPathFactory xpathFactory = XPathFactory.newInstance();
		XPath xpath = xpathFactory.newXPath();
		String lng = xpath.evaluate("//GeocodeResponse/result/geometry/location/lng[1]", new InputSource(new StringReader(xml)));
		String lat = xpath.evaluate("//GeocodeResponse/result/geometry/location/lat[1]", new InputSource(new StringReader(xml)));
		System.out.println("lng=" + lng);
		System.out.println("lat=" + lat);


Necessary minimum to start write a test using Java

In mathematic if you want to do a basic calculation you should know at least numbers from 1 to 10 and simple main operations such as add or subtract. 924 more words


JUnit 4 - @BeforeClass

Using the BeforeClass annotation to load data or classes that are needed by more than one test in a test class:
import ...marc21Utilities.NameAndCodeDTO;
import ...marc21Utilities.VoyagerMarcUtility;
132 more words


Pragmatic Programming in Java 8 with JUnit

Jeff Langr recently put out a new book Pragmatic Unit Testing in Java 8 with JUnit which I highly recommend. I’ve recently come back to Java (mostly through teaching XP courses) and wanted a refresher on some unit testing best practices. 235 more words


An adapter to use Hamcrest matchers as AssertJ conditions

Following on from yesterday’s post on AssertJ, here’s a tiny github repo that I put together with some utilities for AssertJ.

The first is the script mentioned yesterday, tidied up a little and renamed. 66 more words

Converting from Hamcrest to AssertJ

Don’t quite know how I missed it all these years, but I only recently discovered AssertJ.  So I’ve started to use it in some of the… 121 more words