zoukankan      html  css  js  c++  java
  • junit忽略测试方法

    JUnit 提供注解 org.junit.Ignore 用于暂时忽略某个测试方法或者说整个类。因为有时候由于测试环境受限,并不能保证每一个测试方法都能正确运行。

    1,方法级别上使用@ignore来注释我们的测试方法,结果就是该方法在测试执行时会被跳过。测试结束后,还可以获取详细的统计信息,不仅包括了测试成功和测

    试失败的次数,也包括了被忽略的测试数目。

    例如下面的代码便表示由于没有了数据库链接,提示 JUnit 忽略测试方法 unsupportedDBCheck:

    package test.junit4test;
    
    import org.junit.Assert;
    import org.junit.Ignore;
    import org.junit.Test;
    
    public class LinkinTest
    {
    	@Ignore
    	@Test
    	public void test1()
    	{
    		Assert.assertTrue(true);
    	}
    
    	@Test
    	public void test2()
    	{
    		Assert.assertTrue(true);
    	}
    
    }
    


    2,类级别上使用@ignore来修饰整个类。这个类中所有的测试都将被跳过。

    package test.junit4test;
    
    import org.junit.Assert;
    import org.junit.Ignore;
    import org.junit.Test;
    
    @Ignore
    public class LinkinTest
    {
    	@Test
    	public void test1()
    	{
    		Assert.assertTrue(true);
    	}
    
    	@Test
    	public void test2()
    	{
    		Assert.assertTrue(true);
    	}
    
    }

    关于上面的忽略测试一定要小心。注解 org.junit.Ignore 只能用于暂时的忽略测试,如果需要永远忽略这些测试,一定要确认被测试代码不再需要这些测试方法,以免忽略必要的测试点。

  • 相关阅读:
    zoj 3792 Romantic Value
    uva 563
    uva 10779 Collectors Problem 网络流
    什么是撞库,如何预防撞库攻击?
    linux install redis-cli
    python远程调试及celery调试
    python HttpServer共享文件
    python引用,浅复制,深复制
    redis 查询key数量
    ubuntu查询可用安装包
  • 原文地址:https://www.cnblogs.com/LinkinPark/p/5232889.html
Copyright © 2011-2022 走看看