Netbeans + Maven + TestNG - 如何从netbeans运行测试套件?

时间:2015-02-20 15:10:44

标签: maven netbeans testng

我在项目的测试包中进行了测试。 我在测试包中的包中也有一些suite.xml文件。

例如:

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="automation_chrome">
    <test name="All tests running in Chrome">
        <parameter name="browser" value="chrome"></parameter>
        <classes>
            <class name="com.company.testsuites.LoginTest">
                <methods>
                     <include name="successfulLogin" />
                </methods>
            </class>
        </classes>
    </test>    
</suite>

测试用例:

package com.company.testsuites;

import com.company.generictestssuites.MainTest;
import org.testng.Assert;

import org.testng.annotations.Test;

public class LoginTest extends MainTest {

    @Test
    public void successfulLogin() throws Exception {
        login("user1@test.com", "123password1");
        Assert.assertEquals(loginPage.getUserLoged(), "Test User 1");
    }
}

我可以右键单击测试并选择“测试文件”选项运行它。 但是当我右键单击suite.xml来运行测试时,它不会运行测试。

结果如下:

T E S T S
-------------------------------------------------------

Results :

Tests run: 0, Failures: 0, Errors: 0, Skipped: 0

我做错了什么?我需要解决这个问题,以便能够通过Maven运行Jenkins的测试。

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.18.1</version>
            <configuration>
                <parallel>methods</parallel>
                <threadCount>3</threadCount>
                <suiteXmlFiles>
                    <suiteXmlFile>chrome.xml</suiteXmlFile>
                    <suiteXmlFile>firefox.xml</suiteXmlFile>
                    <suiteXmlFile>iexplorer.xml</suiteXmlFile>
                </suiteXmlFiles>
            </configuration>  
        </plugin>

可悲的是,我找不到任何完整的文档来做到这一点。

1 个答案:

答案 0 :(得分:0)

我可以通过这两个变化来实现它:

1-在P​​OM文件中:

                  <suiteXmlFiles>
                    <suiteXmlFile>${project.build.testSourceDirectory}/chrome.xml</suiteXmlFile>
                    <suiteXmlFile>${project.build.testSourceDirectory}/firefox.xml</suiteXmlFile>
                    <suiteXmlFile>${project.build.testSourceDirectory}/iexplorer.xml</suiteXmlFile>
                </suiteXmlFiles>

2-将xml文件(套件)移动到TestPackages中的默认包。

相关问题