本文介绍了junitparameter异常方法应该没有参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
通过使用JUnitParameter测试方法我有一个例外。我的代码类似于JUnitParameter上的大量示例:
By using JUnitParameter for testing a methode I have an exception. My code is similar to lot of example on JUnitParameter:
private Object parametersForTestSetDistanceFormated() {
return new Object[][]{
{100, "_1,__ km"},
{100, "1_,__ km"},
{1100, "11,__ km"},
{110, "1_,1_ km"},
{111, "1_,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
我在网上找不到相关内容...
I haven't found related on the web...
我的全部内容:
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, "_1,__ km"},
{100, "1_,__ km"},
{1100, "11,__ km"},
{110, "1_,1_ km"},
{111, "1_,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());
}
推荐答案
进口需要像:
import com.entities.Client;
import junitparams.JUnitParamsRunner;
import junitparams.Parameters;
import static org.junit.Assert.*;
import org.junit.Test;
import org.junit.runner.RunWith;
现在可以使用
这篇关于junitparameter异常方法应该没有参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!