Junit是一个很好用的单元测试工具,下面是使用Junit来测试方法的简单案例:

import java.util.ArrayList;
import java.util.Iterator;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test; public class JunitCase {
@Before
public void testBefore()
{
System.out.println("在任何方法前都会运行。。。。。。。。。。。。。");
}
@Test
public void test1()
{
System.out.println("111111111111111111111111");
}
@Test
public void test2()
{
ArrayList<Integer>list=new ArrayList<Integer>();
list.add(2222);list.add(3333);list.add(4444);
Iterator<Integer>iterator=list.iterator();//迭代器遍历
while(iterator.hasNext())
{
System.out.print(iterator.next());
}
System.out.println();
}
@Test
public void test3()
{
int num=9;
Assert.assertEquals(num, 9); //断言
}
@Ignore
public void testIgnore()
{
System.out.println("运行时会忽视这个方法。。。。。。。。。");
}
@After
public void testAfter()
{
System.out.println("在任何方法运行后都会运行。。。。。。。。。。。。。");
}
}

运行截图:

Junit的简单使用的更多相关文章

  1. junit的简单用法

    之前测试一个方法总要写一个main函数来调用,感觉既费事又有点low.今天来简单研究一下怎么使用junit来进行单元测试. 1. 依赖包 <dependency> <groupId& ...

  2. myeclipse的安装与配置和JUnit的简单使用

    安装配置 首先根据自己电脑系统选择合适的JDK版本 http://www.oracle.com/technetwork/java/javase/downloads/index.html 这是JDK下载 ...

  3. Appium + junit 的简单实例

    import static junit.framework.Assert.assertTrue; import static org.junit.Assert.*; import org.junit. ...

  4. Junit 学习1 junit的简单使用

    package junit; import java.sql.Connection; import java.sql.SQLException; import org.junit.Test; impo ...

  5. 使用junit和eclemma进行简单的代码测试

    1.Junit和Hamcrest的安装 可以在https://mvnrepository.com/上面下载所需要的Junit和Hamcrest的jar包,然后在项目中新建一个lib文件夹,将下载好的j ...

  6. 【IDEA】单元测试:项目中引入JUnit测试框架+Mock简单了解

    一.Junit 使用和说明: 参考:单元测试第三弹--使用JUnit进行单元测试-HollisChuang's Blog http://www.hollischuang.com/archives/17 ...

  7. 简单了解junit的使用

    普通使用: 在没有用测试框架之前,我们要用一个main方法来跑代码,而有了像junit这样的测试框架后,就可以不用次次写个main方法了. 直接上代码,注释里有说明: package com.stuP ...

  8. [Android]使用自定义JUnit Rules、annotations和Resources进行单元测试(翻译)

    以下内容为原创,欢迎转载,转载请注明 来自天天博客:http://www.cnblogs.com/tiantianbyconan/p/5795091.html 使用自定义JUnit Rules.ann ...

  9. Junit使用

    eclipse Junit的简单使用: eclipse自带了Junit插件. 安装Junit,如下图所示,右键项目-->Properties-->Add Library 选择Junit 选 ...

随机推荐

  1. ACM/ICPC 之 一道不太简单的DP面试题(Geeksforgeeks)

    题面来源:geeksforgeeks/1993 题解:geeksforgeeks 题目简述:给一个m*n的矩阵,计算从(1,1)到(m,n)的所有不回退路径中,经过k次转向后的路径有多少条 输入T个样 ...

  2. codeforces 425D Sereja and Squares n个点构成多少个正方形

    输入n个点,问可以构成多少个正方形.n,xi,yi<=100,000. 刚看题的时候感觉好像以前见过╮(╯▽╰)╭最近越来越觉得以前见过的题偶尔就出现类似的,可是以前不努力啊,没做出来的没认真研 ...

  3. Match:Blue Jeans(POJ 3080)

    DNA序列 题目大意:给你m串字符串,要你找最长的相同的连续字串 这题暴力kmp即可,注意要按字典序排序,同时,是len<3才输出no significant commonalities #in ...

  4. uva 489.Hangman Judge 解题报告

    题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...

  5. python数据库(mysql)操作

    http://fantefei.blog.51cto.com/2229719/1282443

  6. php正则表达式、数组

    <?php $s = "he8llo5wor6ld"; $s = preg_replace("/\d/","#",$s);按照正则表达 ...

  7. UI课堂笔记

    2016.7.18 + (UIColor *)blackColor; + (UIColor *)darkGrayColor;   深灰色 + (UIColor *)lightGrayColor;  浅 ...

  8. supersr--时间显示逻辑-->NSDate+NSCalendar

    一种:时间逻辑: - (NSString *)created_at{ //    从后台返回的字符串格式:Mon Aug 03 09:17:31 +0800 2014, //NSDateFormatt ...

  9. [Android Pro] Android 官方推荐 : DialogFragment 创建对话框

    转载请标明出处:http://blog.csdn.net/lmj623565791/article/details/37815413 1. 概述 DialogFragment在android 3.0时 ...

  10. 建立controller

    复制controller,重建controller 改: @Controller("[productController]") @RequestMapping("/[pr ...