无法正确使用某些Junit类

时间:2013-07-10 12:08:56

标签: java junit junit4 junit-rule

我想在jUnit中使用ErrorCollector类,但无法导入其所需的类。 我想要导入org.junit.rule.*,但我可以选择导入import sun.org.mozilla.javascript.internal.ast.ErrorCollector。我不明白发生了什么。我没有获得导入Rule类的任何选项,我尝试键入import org.junit.rule但未成功导入。 请帮忙或解释一下发生了什么事?

感谢。

package testcases;

import junit.framework.Assert;
import org.junit.Test;
//import sun.org.mozilla.javascript.internal.ast.ErrorCollector;

public class understandingAssertion {

    @Rule
    public ErrorCollector er = new ErrorCollector();

    @Test
    public void countFriendTest() {
        int actual_fr = 100; //Selenium
        int expected_Fr =10;

        /*
        if (actual_fr == expected_Fr) {
            System.out.println("Pass");
        } else {
            System.out.println("Fail");
        }
        */

        System.out.println("A");
        try
        {
            Assert.assertEquals(expected_Fr, actual_fr);
        }
        catch(Throwable e)
        {
            System.out.println("Error encountered");
        }
    }
}

1 个答案:

答案 0 :(得分:0)

您的IDE可能只会为您提供导入类路径中存在的类的选项。

将jar添加到类路径中,您将能够无错误地导入该类。