美文网首页
2019-04-11

2019-04-11

作者: 迷迷糊糊的番薯 | 来源:发表于2019-04-11 13:43 被阅读0次

JUnit

时间测试
@Test(timeout = 10000)
参数化测试
@RunWith(Parameterized.class)
public class ParameterTest{
  @Parameterized.Parameters
  public static Collection<Object[]> testParameters(){
    return Arrays.asList(new Object[][]{
      {1,"hlx"},
      {3,"beyond"},
      {6,"haha"}
    });
  }
}
异常测试
@Test(expected = ArithmeticException.class)
测试套件
@RunWith(Suite.class)
@Suite. SuiteClasses({
  TestJunit1.class,
  TestJunit2.class,
  TestJunit3.class
})
public class TestSuite{
}
Junit--API
  • Assert
  • TestCase
  • TestResult
  • TestSuite

TestNG

时间测试
@Test(timeOut = 10000)
忽略测试
@Test(enabled = false)
public void testIgnore(){
}
分组测试
//单个方法分组
@Test(groups="")
public void testGroup(){
}
//整个类分组
@Test(groups="")
public class TestGroup{
}
依赖测试
@Test(dependsOnMethods = { "method1" })
public void testDepend(){
}

@Test(dependsOnGroups="deploy")
public void testDepend1(){
}
多线程测试
@Test(threadPoolSize = m, invocationCount = n, timeOut = i)
//threadPoolSize多少个线程执行该方法,invocationCount被执行次数,timeOut每次执行该方法的超时时间
参数化测试
1. @Parameter
2. @DataProvider

Junit4和TestNG的区别

  1. Junit4不支持依赖测试
  2. Junit4不支持分组测试
  3. @BeforeClass和@AfterClass在junit4中必须声明作为静态方法

相关文章

网友评论

      本文标题:2019-04-11

      本文链接:https://www.haomeiwen.com/subject/lhoziqtx.html