java – junitparameter异常方法应该没有参数

前端之家收集整理的这篇文章主要介绍了java – junitparameter异常方法应该没有参数前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
通过使用JUnitParameter来测试方法我有一个例外.我的代码类似于JUnitParameter上的大量示例:
private Object parametersForTestSetDistanceFormated() {
    return new Object[][]{    
        {100,"_1,__ km"},{100,"1_,{1100,"11,{110,1_ km"},{111,11 km"}};
}
/**
 * Test of setDistanceFormated method,of class ClientFormated.
 */
@Test
@Parameters
public void testSetDistanceFormated(final int exptDist,final String  distFormated) {
    System.out.println("setDistanceFormated");
    ClientFormated instance = new ClientFormated();             

    instance.setDistanceFormated(distFormated);
    assertEquals(exptDist,(long) instance.getDistance());
}

然后我获得以下异常:

java.lang.RuntimeException: java.lang.Exception: Method testSetDistanceFormated should have no parameters
    at junitparams.JUnitParamsRunner.verifyMethodCanBeRunByStandardRunner(JUnitParamsRunner.java:429)
    at junitparams.JUnitParamsRunner.runChild(JUnitParamsRunner.java:420)
    at junitparams.JUnitParamsRunner.runChild(JUnitParamsRunner.java:386)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:53)
    at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:123)
    at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:104)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:164)
    at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:110)
    at org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:175)
    at org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcessWhenForked(SurefireStarter.java:107)
    at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:68)
Caused by: java.lang.Exception: Method testSetDistanceFormated should have no parameters
    at org.junit.runners.model.FrameworkMethod.validatePublicVoidNoArg(FrameworkMethod.java:76)
    at junitparams.JUnitParamsRunner.verifyMethodCanBeRunByStandardRunner(JUnitParamsRunner.java:427)
    ... 20 more

我没有在网上找到相关内容……

我的全体意见:

import com.entities.Client;
import junitparams.JUnitParamsRunner;
import org.junit.Test;
import static org.junit.Assert.*;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized.Parameters;

@RunWith(JUnitParamsRunner.class)
public class ClientFormatedTest {

private Object parametersForTestSetDistanceFormated() {
    return new Object[][]{    
        {100,11 km"}};
}

/**
 * Test of setDistanceFormated method,(long) instance.getDistance());
}

解决方法

在类上面添加@RunWith(JUnitParamsRunner.class)注释
@RunWith(JUnitParamsRunner.class)
public class TestClass {

你还需要导入

import junitparams.JUnitParamsRunner;
原文链接:https://www.f2er.com/java/125934.html

猜你在找的Java相关文章