2
工作我使用下面的測試運行:http://code.google.com/p/migen/source/browse/trunk/java/src/uk/ac/lkl/common/util/testing/LabelledParameterized.java?r=3789重載參數測試運行不JUnit4Provider
它所做的是改變的參數測試的名稱是更具可讀性。即:預期的結果 - 「myDefinedTestName」
當我運行使用eclipse它能正常工作:我可以看到新的名稱。 當我運行使用JUnit4Provider:
final JUnit4Provider provider = new JUnit4Provider(params);
provider.invoke(testClass);
事實並非如此。即:我得到「oldTestName [0]」。沒有錯誤。爲什麼以及如何解決這個問題?
我試過使用JUnitCore沒有成功。使用測試運行
的TestRunner
import org.junit.runner.JUnitCore;
public class TestRunner {
/**
* @param args
*/
public static void main(final String[] args) {
final JUnitCore provider = new JUnitCore();
provider.addListener(new TestJUnitCore4Listener());
provider.run(UpdateBackgroundImageParameterizedTests.class);
}
}
監聽
import org.junit.runner.Description;
import org.junit.runner.notification.RunListener;
public class TestJUnitCore4Listener extends RunListener {
@Override
public void testFinished(final Description description) throws Exception {
System.out.println(description.getDisplayName() + " "
+ description.getMethodName());
}
}
測試
import static org.junit.Assert.assertTrue;
import java.util.Arrays;
import java.util.Collection;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized.Parameters;
@RunWith(LabelledParameterized.class)
public class UpdateBackgroundImageParameterizedTests {
// Fields
private final String datum;
private final String expectedResult;
/**
* Constructor is called for every parameter set in generateData()
*
* @param datum
* input to be used in tests
* @param expectedResult
* output expected by tests
*/
public UpdateBackgroundImageParameterizedTests(final String datum,
final String expectedResult) {
super();
this.datum = datum;
this.expectedResult = expectedResult;
}
/**
* @return a list of expected inputs and outputs
*/
@Parameters
public static Collection<Object[]> generateData() {
return Arrays.asList(new Object[][] { { "sunny", "a" }, // 0
{ "cloudy", "a" }, // "a"
{ "rain", "a" }, // 2
{ "heavy snow", "a" }, // 3
{ "occasionally thundery", "a" }, // 4
{ "clear skies", "a" }, // 5
{ "error", "a" } }); // 6
}
/**
* Test updateBackgroundImage using parameter injection for feed Test run
* for all parameters specified in generateData()
*
* @throws Exception
*/
@Test
public void testUpdateBackgroundImage() throws Exception {
assertTrue(true);
}
}
我š給出的輸出:
testUpdateBackgroundImage[0](UpdateBackgroundImageParameterizedTests) testUpdateBackgroundImage[0]
testUpdateBackgroundImage[1](UpdateBackgroundImageParameterizedTests) testUpdateBackgroundImage[1]
testUpdateBackgroundImage[2](UpdateBackgroundImageParameterizedTests) testUpdateBackgroundImage[2]
testUpdateBackgroundImage[3](UpdateBackgroundImageParameterizedTests) testUpdateBackgroundImage[3]
testUpdateBackgroundImage[4](UpdateBackgroundImageParameterizedTests) testUpdateBackgroundImage[4]
testUpdateBackgroundImage[5](UpdateBackgroundImageParameterizedTests) testUpdateBackgroundImage[5]
testUpdateBackgroundImage[6](UpdateBackgroundImageParameterizedTests) testUpdateBackgroundImage[6]
JUnit4Provider從哪裏來?它給了什麼錯誤?你如何與供應商一起運行代碼?你可以多給一點背景嗎? – 2012-03-02 08:16:45
增加了更多細節。謝謝。 – ET13 2012-03-02 09:38:28