View Ravichandran J.V.'s profile on LinkedIn RJV 's Blog: Parameterized test with HashMap example - JUnit Tweet @ravichandranjv


Sunday, 11 November 2012

Parameterized test with HashMap example - JUnit

A rather contrived example but since there is a dearth of JUnit example on parametrized tests on the web it should help plus JUnit parameters is itself a little contrived ! :) Theories and Datapoints are a better option...will post soon on Theories.

package parameterTests;

import static org.junit.Assert.*;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;

public class ParameterAnnotation {
private Map geo;
public static Collection configs() { Map geo1 = new HashMap(); geo1.put("Country", "India"); geo1.put("Capital", "New Delhi"); return Arrays.asList(new Object[][] { { geo1 } }); }      public ParameterAnnotation(Map geo) {
        this.geo = geo;

public void pushTest1() {
    assertEquals("India", geo.get("Country"));
    assertEquals("New Delhi", geo.get("Capital"));

No comments: