J
jeppe.epeli
Hi,
I just don't understand why this test code doesn't work with Junit 4:
-------------------------------------------
import static org.junit.Assert.assertEquals;
import java.awt.geom.Point2D;
import java.util.LinkedList;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
@RunWith(Parameterized.class)
public class ParametricTest {
private DataItem dI;
public ParametricTest(DataItem dI) {
this.dI=dI;
}
@Parameters
public static LinkedList data() {
float x,y;
LinkedList params = new LinkedList();
x=0.0f;
y=0.0f;
params.add(new DataItem(x, y, new Point2D.Float(x,y)));
x+=1.0f;
params.add(new DataItem(x, y, new Point2D.Float(x,y)));
return params;
}
@Test
public void testPoint() {
assertEquals(dI.x, dI.p.x);
assertEquals(dI.y, dI.p.y);
}
private static class DataItem {
private float x, y;
private Point2D.Float p;
public DataItem(float x, float y, Point2D.Float p) {
this.x=x;
this.y=y;
this.p=p;
}
}
}
-------------------------------------------
When I run JUnit test, JUnit returns initializationError0 before
executing constructor of class ParametricTest. When I replace rows
params.add(new DataItem(x, y, new Point2D.Float(x,y)));
with rows
params.add(new Object[] { new DataItem(x, y, new
Point2D.Float(x,y))});
test runs correctly. Do I really have to include 'new Object[] {...} '
in my test?
Please help me...I'm new with JUnit...
-Jeppe
I just don't understand why this test code doesn't work with Junit 4:
-------------------------------------------
import static org.junit.Assert.assertEquals;
import java.awt.geom.Point2D;
import java.util.LinkedList;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
@RunWith(Parameterized.class)
public class ParametricTest {
private DataItem dI;
public ParametricTest(DataItem dI) {
this.dI=dI;
}
@Parameters
public static LinkedList data() {
float x,y;
LinkedList params = new LinkedList();
x=0.0f;
y=0.0f;
params.add(new DataItem(x, y, new Point2D.Float(x,y)));
x+=1.0f;
params.add(new DataItem(x, y, new Point2D.Float(x,y)));
return params;
}
@Test
public void testPoint() {
assertEquals(dI.x, dI.p.x);
assertEquals(dI.y, dI.p.y);
}
private static class DataItem {
private float x, y;
private Point2D.Float p;
public DataItem(float x, float y, Point2D.Float p) {
this.x=x;
this.y=y;
this.p=p;
}
}
}
-------------------------------------------
When I run JUnit test, JUnit returns initializationError0 before
executing constructor of class ParametricTest. When I replace rows
params.add(new DataItem(x, y, new Point2D.Float(x,y)));
with rows
params.add(new Object[] { new DataItem(x, y, new
Point2D.Float(x,y))});
test runs correctly. Do I really have to include 'new Object[] {...} '
in my test?
Please help me...I'm new with JUnit...
-Jeppe