首页 > 其他 > 详细

Junit(一)

时间:2015-11-11 22:06:47      阅读:312      评论:0      收藏:0      [点我收藏+]

一、一手鞋

  官网地址:http://junit.org/

二、搭建过程

  较简单,略

三、Getting Started

  Eclipse中可直接引入JUnit4包使用

四、使用技巧

      (一) Assertions 断言

   1. 可重载(Overload),第一个参数通常为错误信息

       2. assertThat于assert不同,错误信息可选,需要Matcher参数

     3. 示例

    (1) assertArrayEquals

                  byte[] expected = "trial".getBytes();

                  byte[] actual = "trial".getBytes();

                  org.junit.Assert.assertArrayEquals("failure - byte arrays not same", expected, actual);

           (2)testAssertEquals

                   org.junit.Assert.assertEquals("failure - strings are not equal", "text", "text");

           (3)testAssertFalse

                   org.junit.Assert.assertFalse("failure - should be false", false);

           (4)testAssertNotNull()

                  org.junit.Assert.assertNotNull("should not be null", new Object());

      (二) Test runners

    1. NetBeans, Eclipse and IntelliJ Idea have native graphical test runners built in.

    2. 示例

      public static Test suite() { return new JUnit4TestAdapter(‘YourJUnit4TestClass.class); }

       (三)Aggregating tests in suites

    1. 集中测试

    2. 示例

     import org.junit.runner.RunWith;

               import org.junit.runners.Suite;

               @RunWith(Suite.class)

               @Suite.SuiteClasses({

                       TestFeatureLogin.class,

                       TestFeatureLogout.class,

                       TestFeatureNavigate.class,

                       TestFeatureUpdate.class })

                 public class FeatureTestSuite {

                       // the class remains empty,

                       // used only as a holder for the above annotations

                  }

  (四)执行顺序

   1. @FixMethodOrder(MethodSorters.JVM)

         2. @FixMethodOrder(MethodSorters.NAME_ASCENDING),按照名称排序

Junit(一)

原文:http://www.cnblogs.com/shangrong/p/4957403.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!