gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-03 03:30:18 24 4
gpt4 key购买 nike

通过使用 JUnitParameter 测试方法,我遇到了一个异常。我的代码类似于 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

我在网上没有找到相关的...

我的全类:

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());
}

最佳答案

在类上方添加@RunWith(JUnitParamsRunner.class) 注解作为

@RunWith(JUnitParamsRunner.class)
public class TestClass {

还需要导入

import junitparams.JUnitParamsRunner;

关于java - junitparameter异常方法应该没有参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37424725/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com