J. *_*rer 6 junit intellij-idea
it is my first day with JUnit. I try to make test with parameters. I have code:
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import static org.junit.Assert.assertEquals;
@RunWith(JUnitParamsRunner.class)
public class MoneyParameterizedTest {
private static final Object[] getMoney() {
return new Object[] {
new Object[] {10, "USD"},
new Object[] {20, "EUR"}
};
}
@Test
@Parameterized.Parameters(method = "getMoney")
public void constructorShouldSetAmountAndCurrency(
int amount, String currency) {
Money money = new Money(amount, currency);
assertEquals(amount, money.getAmount());
assertEquals(currency, money.getCurrency());
}
}
Run Code Online (Sandbox Code Playgroud)
IntelliJ told me that: Can't resolve symbol JUnitParamsRunner and method. Is it problem with import? My class which I'm testing is in the same package.
----- EDIT -------
我将JunitParamsrunner.class更改为Parameterized.class,这没关系,但是Parametrized.Parameters中的符号“ method”存在问题。
JUnitParams(获得许可的 Apache 2.0)是一个单独的库,这意味着它没有随 JUnit 本身一起提供。这也意味着您需要确保它位于项目的类路径中。如果您使用的是 maven(或类似的东西),那么它很容易,您只需要将它作为依赖项添加到您的 pom 中,并确保 IJ 已获取更改(如果它在右上角):
<dependency>
<groupId>pl.pragmatists</groupId>
<artifactId>JUnitParams</artifactId>
<version>1.0.5</version>
<scope>test</scope>
</dependency>
Run Code Online (Sandbox Code Playgroud)
否则,请自行下载(单击Download ( JAR )链接)并将其库下载到您的类路径中。
请注意,虽然概念相似,但与Parameterized不是一回事JUnitParams,后者试图简化和改进编写参数化 JUnit 测试的方式。
PS:还有一个叫做的库Zohhak,它看起来比JUnitParams它更灵活,但它是根据LGPL 3.0你的许可限制发布的。
| 归档时间: |
|
| 查看次数: |
4482 次 |
| 最近记录: |