The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

troys (1) [Avatar] Offline
#1
I'm trying to compile the example from chap 2.

import static org.junit.Assert.*;
import org.junit.Test;
@RunWith(value=Parameterized.class)
public class ParameterizedTest {
private double expected;
private double valueOne;
private double valueTwo;
@Parameters
public static java.util.Collection dataParameters() {
return java.util.Arrays.asList(new Object[][] {
{2,1,1}, //expected, valueOne, valueTwo
{3,2,1},
{4,3,1},
});
}
public ParameterizedTest(double expected,
double valueOne, double valueTwo) {
this.expected = expected;
this.valueOne = valueOne;
this.valueTwo = valueTwo;
}
@Test
public void sum() {
Calculator calc = new Calculator();
assertEquals(expected, calc.add(valueOne, valueTwo), 0);
}
}

I get the following errors.

$ javac -cp ".;c:junit4.5junit-4.5.jar;c:junit4.5" ParameterizedTest.java 2>
&1|less
ParameterizedTest.java:3: cannot find symbol
symbol: class RunWith
@RunWith(value=Parameterized.class)
^
ParameterizedTest.java:8: cannot find symbol
symbol : class Parameters
location: class ParameterizedTest
@Parameters
^
2 errors
felipe.leme (18) [Avatar] Offline
#2
Re: Probmems with RunsWith
Hi Troy,

First of all, sorry for nobody had answered your question yet - apparently, we haven't received any forum notifications recently.

Anyways, it looks like the sample code is missing the following imports:

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

Please add these lines, try again, and let us know if you still have problems.

-- Felipe