TestNG 跳过测试 - 为什么? [英] TestNG skipping tests - why?

查看:47
本文介绍了TestNG 跳过测试 - 为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 testng 和 selenium 测试一个网络应用程序.测试主要包括打开应用程序的几个页面,并针对每个页面执行一些特定的活动.所以我有一个执行打开页面"测试的抽象基类,它定义了一个抽象方法,用作该测试的数据提供者.然后有几个扩展类为数据提供者提供实现,并且除了基类的测试之外还有几个不同的测试.我有一个 testsuite.xml,其中包含所有类,这是我从 eclipse 中运行的.

I am testing a web app with testng and selenium. The tests mainly consist in opening several pages of the app, and do some activities specific for each page. So I have an abstract base class which performs the "open page" test, and that defines an abstract method which is used as data provider for that test. Then there are several extending classes which provide implementation for the data provider, and which have several different tests apart from that of the base class. I have a testsuite.xml where all the classes are included, which is what I run from my eclipse.

问题是,当我启动测试执行时,testng 在所有对象的基类中运行测试,但系统地跳过扩展类中的所有其他测试.有谁知道为什么?任何信息将不胜感激...

The problem is that when I launch the test execution, testng runs the test in the base class for all objects, but skips systematically every other tests in the extending classes. Does anyone know why? Any information will be very appreciated...

为了完成信息,以下是我使用的一些类和 xml:

To complete information, here are some of the classes and the xml I use:

基类:

public abstract class BaseWebAppPageTest {

    @Test(dataProvider="getMenuLink")
    public void testOpen(String menulink){
        GenericPageActions.openPage(TestingContext.getSelenium(), menulink);
    }

    protected abstract String[][] getMenuLink();

}

还有一些扩展类:

测试语言:

public class TestLanguages extends BaseWebAppPageTest{

    @Test(dependsOnMethods={"testOpen"}, dataProvider="getCreateData")
    public void testCreateCorrect(String code, String description, String textDirection, String flag){
        Selenium selenium = TestingContext.getSelenium();
        LanguagesManagementActions.create(selenium, code, description, textDirection, flag);
    Assert.assertTrue(selenium.isTextPresent("Successfully created language"));
    }

    @Test(dependsOnMethods={"testCreateCorrect"}, dataProvider="getCreateData")
    public void testFilter(String code, String description, String textDirection, String flag){
        Selenium selenium = TestingContext.getSelenium();
        LanguagesManagementActions.filterTable(selenium, 2, code, 30000);
    Assert.assertTrue(selenium.getXpathCount("xpath=//span[.='"+code+"']").intValue() == 1);
    }

    @Test(dependsOnMethods={"testCreateCorrect"}, dataProvider="getCreateData")
    public void testModify(String code, String description, String textDirection, String flag){
        Selenium selenium = TestingContext.getSelenium();
        LanguagesManagementActions.modify(TestingContext.getSelenium(), code, description, textDirection, flag);
        Assert.assertTrue(selenium.isTextPresent("Successfully updated language"));
    }

    @Override
    @DataProvider
    protected String[][] getMenuLink() {
        return(TestingContext.getDataReader().getTableArray("openviewpage", "MULTILINGUAL_LANGUAGES"));
    }

    @DataProvider
    protected String[][] getCreateData() {
        return(TestingContext.getDataReader().getTableArray("multilingualcreate", "LANGUAGES"));
    }

}

测试翻译:

public class TestTranslations extends BaseWebAppPageTest{

@Test(dependsOnMethods={"testOpen"}, dataProvider="getCreateData")
public void createCorrect(String code, String targetLanguage, String translation){
    Selenium selenium = TestingContext.getSelenium();
    TranslationsManagementActions.create(selenium, code, targetLanguage, translation);
    Assert.assertTrue(selenium.isTextPresent("Successfully created translation"));
}

@Test(dependsOnMethods={"createCorrect"}, dataProvider="getCreateData")
public void update(String code, String targetLanguage, String translation){
    Selenium selenium = TestingContext.getSelenium();
    TranslationsManagementActions.update(selenium, code, targetLanguage, translation);
    Assert.assertTrue(selenium.isTextPresent("Successfully updated translation"));
}

@Test(dependsOnMethods={"createCorrect"}, dataProvider="getCreateData")
public void filter(String code, String targetLanguage, String translation){
    Selenium selenium = TestingContext.getSelenium();
    TranslationsManagementActions.filterTable(selenium, 2, code, 30000);
    Assert.assertTrue(selenium.isElementPresent("xpath=//span[.='"+translation+"']"));
}

@Override
@DataProvider
protected String[][] getMenuLink() {
    return(TestingContext.getDataReader().getTableArray("openviewpage", "MULTILINGUAL_TRANSLATIONS"));
}

@DataProvider
protected String[][] getCreateData() {
    return(TestingContext.getDataReader().getTableArray("multilingualcreate", "TRANSLATIONS"));
}

}

最后,TestSuite.xml:

And finally, the TestSuite.xml:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE suite SYSTEM "http://beust.com/testng/testng-1.0.dtd" >
    <suite name="WebAppSuiteTest" parallel="none">
      <parameter name="selenium.host" value="localhost" />
      <parameter name="selenium.port" value="5555" />
      <parameter name="selenium.browser" value="*firefox3 C:\\Documents and Settings\\dgarcia\\Local Settings\\Application Data\\Mozilla Firefox\\firefox.exe" />
      <parameter name="selenium.url" value="http://localhost:8080/standard-webapp-war/home.seam" />
      <parameter name="selenium.timeout" value="1000000" />
      <parameter name="test.data.filepath" value="src\\test\\resources\\datatest_.xls" />

  <test name="standard" preserve-order="true" >
    <classes>
        <class name="com.standard.webapp.common.TestingContext" />      
        <class name="com.standard.webapp.login.TestLogin"/>
        <class name="com.standard.webapp.TestLanguages"/>
        <class name="com.standard.webapp.TestTranslations"/>
        </class>
    </classes>
  </test>
</suite>

<小时>

输出中没有任何例外也没有任何理由跳过这些测试.我不太确定你提到的输出,所以我将在此处粘贴生成的myWebAppTest.xml"的内容和测试结果:


there is no exception nor any reason on the output to skip those tests. I am not really sure about the output you mention, so I will paste here the content of the generated "myWebAppTest.xml" with the results of the tests:

<testsuite hostname="SP2L0044" name="com.sicpa.standard.dms.webapp.selenium.common.BaseWebAppPageTest" tests="14" failures="0" timestamp="4 Mar 2011 08:45:57 GMT" time="27.141" errors="0">
  <testcase name="testLoginLoadHome" time="2.188" classname="com.sicpa.standard.dms.webapp.selenium.login.TestLogin"/>
  <testcase name="testCreateCorrect" time="0.0" classname="com.sicpa.standard.dms.webapp.selenium.multilingual.TestCodes">
    <skipped/>
  </testcase>
  <testcase name="testFilter" time="0.0" classname="com.sicpa.standard.dms.webapp.selenium.multilingual.TestCodes">
    <skipped/>
  </testcase>
  <testcase name="testUpdate" time="0.0" classname="com.sicpa.standard.dms.webapp.selenium.multilingual.TestCodes">
    <skipped/>
  </testcase>
  <testcase name="testView" time="0.0" classname="com.sicpa.standard.dms.webapp.selenium.multilingual.TestCodes">
    <skipped/>
  </testcase>
  <testcase name="testCreateCorrect" time="0.0" classname="com.sicpa.standard.dms.webapp.selenium.multilingual.TestLanguages">
    <skipped/>
  </testcase>
  <testcase name="testFilter" time="0.0" classname="com.sicpa.standard.dms.webapp.selenium.multilingual.TestLanguages">
    <skipped/>
  </testcase>
  <testcase name="testModify" time="0.0" classname="com.sicpa.standard.dms.webapp.selenium.multilingual.TestLanguages">
    <skipped/>
  </testcase>
  <testcase name="createCorrect" time="0.0" classname="com.sicpa.standard.dms.webapp.selenium.multilingual.TestTranslations">
    <skipped/>
  </testcase>
  <testcase name="filter" time="0.0" classname="com.sicpa.standard.dms.webapp.selenium.multilingual.TestTranslations">
    <skipped/>
  </testcase>
  <testcase name="update" time="0.0" classname="com.sicpa.standard.dms.webapp.selenium.multilingual.TestTranslations">
    <skipped/>
  </testcase>
  <testcase name="testOpen" time="2.297" classname="com.sicpa.standard.dms.webapp.selenium.multilingual.TestLanguages"/>
  <testcase name="testOpen" time="12.61" classname="com.sicpa.standard.dms.webapp.selenium.multilingual.TestCodes"/>
  <testcase name="testOpen" time="9.469" classname="com.sicpa.standard.dms.webapp.selenium.multilingual.TestTranslations"/>
</testsuite>

推荐答案

TestNG 跳过测试的原因有多种,最常见的一个是您依赖的方法(例如 testOpen 或 createCorrect)以某种方式失败.

There are various reasons why TestNG is skipping the tests, the most common one is that a method you depend on (e.g. testOpen or createCorrect) failed in some way.

我建议将详细级别设置为 10 并将输出粘贴到此处或 testng-users 邮件列表上.

I suggest setting the verbose level to 10 and paste the output here or on the testng-users mailing-list.

如果您使用的是 XML 定义,请像这样设置详细级别:<suite name="sweet_suite" verbose="10">.也可以通过代码配置来设置详细程度.

If you are using an XML definition, set the verbose level like so: <suite name="sweet_suite" verbose="10">. The verbosity level can also be set through code configuration.

TestNG tng = new TestNG();
XmlSuite suite = new XmlSuite();

suite.setVerbose(10);

// other configuration, add tests to run

List<XmlSuite> suites = new ArrayList<XmlSuite>();
suites.add( suite );
tng.setXmlSuites(suites);
tng.run();

这篇关于TestNG 跳过测试 - 为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆