如何暂时禁用 Junit 测试运行?

3
我有以下 Junit 测试类.
package Md5Tests;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*;
import timebackup.*;

/**
 *
* @author jack
*/
public class PathNodeToXmlTest {

public PathNodeToXmlTest() {
}

@Before
public void setUp() {
}

@After
public void tearDown() {
}

@Test
public void createXml() {
    PathNode root = new PathNode(true, "docs", "0");
    root.addPathNode(new PathNode(true, "docs sub folder", "1"));
    root.addPathNode(new PathNode(false, "docs sub file", "2"));
    PathNodeToXml xmlCreator = new PathNodeToXml(root);
    System.out.println(xmlCreator);
}
}

我现在想要暂时阻止测试运行器运行 createXml() 测试方法。我尝试在 @Test 注释之前添加 @Ignore 注释,但编译器报错说找不到 @Ignore 的标志符号。我正在使用 NetBeans IDE。

请问有没有其他方法来临时防止 JUnit 测试运行?


1
注释掉测试注解,例如 //@Test - Darshan Mehta
3
为确保无误,请将 import org.junit.Ignore; 添加到导入列表中以使用 @Ignore - default locale
@DarshanMehta 它没有起作用,我仍然收到编译器错误。 - SteelToe
1
@defaultlocale 它像魔法一样运行正常,谢谢 - SteelToe
1个回答

7

@Ignore 注解位于 org.junit 包中,因此您需要添加 import 语句。

import org.junit.Ignore;

或者
import org.junit.*;

下次遇到这样的问题,你可以直接在Google搜索类名(例如junit @Ignore),进入文档页面并检查包名。
在NetBeans中,您可以使用“源 -> 修复导入”命令(Ctrl + Shift + I),IDE会尝试自动解决必要的导入。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接