实例化属性:groups & methods

上一篇 / 下一篇  2012-04-25 16:02:04 / 个人分类:TestNG/Ant/Eclipse/Java

newTest.java:
package bao;
import org.testng.annotations.*;
  
public class NewTest { 
 
 @Test(groups = { "fast" })  
 public void aFastTest() { 
   System.out.println("Fast test"); 
 } 
  
 @Test(groups = { "slow" }) 
 public void aSlowTest() { 
 System.out.println("Slow test"); 
 }    
}
xml文件调methods:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite" parallel="none">
  <test name="Test" preserve-order="true">
    <classes>
      <class name="bao.NewTest">
        <methods> 
        <include name="aFastTest" /> 
        <exclude name="aSlowTest" /> 
       </methods>     
      </class>
    </classes>
  </test> <!-- Test -->
</suite> <!-- Suite -->
 
xml文件调groups
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite" parallel="none">
  <test name="Test" preserve-order="true">
<groups>
   <run>  
      <exclude name="fast" /> 
      <include name="slow" /> 
   </run> 
  </groups> 
    <classes>
      <class name="bao.NewTest"/>
    </classes>
  </test> <!-- Test -->
</suite> <!-- Suite -->
 
tips:
 
Not only can you declare that methods belong to groups, but you can also specify groups that contain other groups. Then TestNG can be invoked and asked to include a certain set of groups
Groups are specified in yourtestng.xmlfile and can be found either under the<test>or<suite>tag.
Groups specified in the<suite>tag apply to all the<test>tags underneath. Note that groups are accumulative in these tags: if you specify group "a" in<suite>and "b" in<test>, then both "a" and "b" will be included.

For example, it is quite common to have at least two categories of tests

  • Check-in tests. These tests should be run before you submit new code. They should typically be fast and just make sure no basic functionality was broken.
  • Functional tests. These tests should cover all the functionalities of your software and be run at least once a day, although ideally you would want to run them continuously.
Typically, check-in tests are a subset of functional tests. TestNG allows you to specify this in a very intuitive way with test groups. For example, you could structure your test by saying that your entire test class belongs to the "functest" group, and additionally that a couple of methods belong to the group "checkintest":
 
public class Test1 { 
  @Test(groups = { "functest", "checkintest" }) 
  public void testMethod1() { 
  } 
  @Test(groups = {"functest", "checkintest"} ) 
  public void testMethod2() { 
  } 
  
  @Test(groups = { "functest" }) 
  public void testMethod3() { 
  } 
}
相对应的xml文件:
<test name="Test1"> 
  <groups> 
    <run> 
      <include name="functest"/> 
    </run> 
  </groups> 
  <classes> 
    <class name="example1.Test1"/> 
  </classes> 
</test>
 

TAG:

 

评分:0

我来说两句

日历

« 2024-05-08  
   1234
567891011
12131415161718
19202122232425
262728293031 

数据统计

  • 访问量: 74500
  • 日志数: 80
  • 建立时间: 2012-04-12
  • 更新时间: 2013-05-21

RSS订阅

Open Toolbar