• 使用@Ignore注解


    断续上一节的例子,了解如何使用@Ignore注解。在测试类FirstDayAtSchoolTest中,我们将添加@Ignore注解到testAddPencils()方法。以这种方式,我们期望这个测试方法将被忽略,不被执行。

    package com.yiibai.junit;
    
    import static org.junit.Assert.*;
    
    import org.junit.Ignore;
    import org.junit.Test;
    
    public class FirstDayAtSchoolTest {
    
    	FirstDayAtSchool school = new FirstDayAtSchool();
    	String[] bag1 = { "Books", "Notebooks", "Pens" };
    	String[] bag2 = { "Books", "Notebooks", "Pens", "Pencils" };
    
    	@Test
    	public void testPrepareMyBag() {
    		System.out.println("Inside testPrepareMyBag()");
    		assertArrayEquals(bag1, school.prepareMyBag());
    	}
    
    	@Ignore
    	@Test
    	public void testAddPencils() {
    		System.out.println("Inside testAddPencils()");
    		assertArrayEquals(bag2, school.addPencils());
    	}
    
    }

    事实上,这输出会发生什么:

    Inside testPrepareMyBag()
    My school bag contains: [Books, Notebooks, Pens]
     

    现在,我们将从testAddPencils()方法去除@Ignore注解,修改为注释整个类来代替。

    package com.yiibai.junit;
    
    import static org.junit.Assert.*;
    
    import org.junit.Ignore;
    import org.junit.Test;
    
    @Ignore
    public class FirstDayAtSchoolTest {
    
    	FirstDayAtSchool school = new FirstDayAtSchool();
    	String[] bag1 = { "Books", "Notebooks", "Pens" };
    	String[] bag2 = { "Books", "Notebooks", "Pens", "Pencils" };
    
    	@Test
    	public void testPrepareMyBag() {
    		System.out.println("Inside testPrepareMyBag()");
    		assertArrayEquals(bag1, school.prepareMyBag());
    	}
    
    	
    	@Test
    	public void testAddPencils() {
    		System.out.println("Inside testAddPencils()");
    		assertArrayEquals(bag2, school.addPencils());
    	}
    
    }

    在这个测试类将不会执行,因此不显示在控制台和JUnit视图输出结果:

  • 相关阅读:
    转贴:C语言链表基本操作
    硬盘上的一些算法小题目||and今天看了下林锐的书以及gdb调试 及一些变成算法小题目
    MFC入门 002 滚动条Scorllbar 数字控制框 Spin 进度条 Progress
    002 Windows数据类型 字符集
    001 Windows 简介
    MFC入门 001 Edit&Button&List&ComboBox
    iPads和iPones的Media Queries
    响应式网页设计
    chrome developer tool 调试技巧
    返回一个整型数组中最大子数组的和(02)
  • 原文地址:https://www.cnblogs.com/borter/p/9608670.html
Copyright © 2020-2023  润新知