相关疑难解决方法(0)

如何将@RunWith与@RunWith(Parameterized.class)结合起来

我实现了一个继承自BlockJUnit4ClassRunner的运行器类A.class,以便我可以用@RunWith(A.class)注释测试.与此同时,某人 else用RunWith(Parameterized.class)注释测试.很明显,我们不能同时使用两个@RunWith.

如何解决这个问题呢?或者如何合并这两个@RunWith?

junit junit-runner

9
推荐指数
1
解决办法
5868
查看次数

如何在 JUnit 4 和 Kotlin for Android 中创建参数化测试用例?

我需要类似于 C# NUnit TestCase场景的东西,具有固定的预期结果。

我已经在 SO 上找到了这个问题,它有很好的解决方案,但它们仅适用于 Java,并且正如我遵循本教程的一些答案中所建议的那样,但简单地将其转换为 Kotlin 是行不通的。

@RunWith(value = Parameterized.class)
public class EmailIdValidatorTest {

    private String emailId;
    private boolean expected;

    public EmailIdValidatorTest(String emailId, boolean expected) {
        this.emailId = emailId;
        this.expected = expected;
    }
    @Parameterized.Parameters(name= "{index}: isValid({0})={1}")
    public static Iterable<Object[]> data() {
        return Arrays.asList(new Object[][]{
                        {"mary@testdomain.com", true},
                        {"mary.smith@testdomain.com", true},
                        {"mary_smith123@testdomain.com", true},
                        {"mary@testdomaindotcom", false},
                        {"mary-smith@testdomain", false},
                        {"testdomain.com", false}
                }
        );
    }
    @Test
    public void testIsValidEmailId() throws Exception {
        boolean actual= EmailIdUtility.isValid(emailId);
        assertThat(actual, is(equalTo(expected)));
    } …
Run Code Online (Sandbox Code Playgroud)

junit android unit-testing kotlin

9
推荐指数
2
解决办法
6335
查看次数

标签 统计

junit ×2

android ×1

junit-runner ×1

kotlin ×1

unit-testing ×1