命令行运行testng用例


1、配置pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0modelVersion>

    <groupId>com.wutonggroupId>
    <artifactId>E-sealartifactId>
    <version>1.0-SNAPSHOTversion>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.pluginsgroupId>
                <artifactId>maven-compiler-pluginartifactId>
                <configuration>
                    <source>1.8source>
                    <target>1.8target>
                configuration>
            plugin>
            <plugin>
                <groupId>org.apache.maven.pluginsgroupId>
                <artifactId>maven-surefire-pluginartifactId>
                <version>2.19version>
                <configuration>
                    <suiteXmlFiles>
                        <suiteXmlFile>testng.xmlsuiteXmlFile>
                    suiteXmlFiles>
                configuration>
            plugin>
        plugins>
    build>
    <properties>
        <project.build.sourceEncoding>UTF-8project.build.sourceEncoding>
    properties>
    <dependencies>
        <dependency>
            <groupId>com.alibabagroupId>
            <artifactId>fastjsonartifactId>
            <version>1.2.60version>
        dependency>

    dependencies>

project>

2、配置testng.xml

<?xml version="1.0" encoding="UTF-8"?>
DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="First suite" verbose="1" >
<test name = "allTestsInAClass" >
   
   <packages>
      <package name = "com.wutong.package.*"/>
   packages>
   
   <classes>
  <class name="com.wutong.package.className"/>
   classes>
   
   <classes>
  <class name="com.wutong.package.className"/>
      <methods>
         <include name = "firstMethod" />
         <include name = "secondMethod" />
         <include name = "thirdMethod" />
      methods>
  class>
   classes>
   
   <groups>
      <run>
         <include name = "includedGroup" />
      run>
   groups>
   <packages>
      <package name = "com.wutong.package.*"/>
   packages>
   
   <groups>
      <run>
         <exclude name = "excludedGroup" />
      run>
   groups>
   <packages>
      <package name = "whole.path.to.package.*"/>
   packages>
test>
suite>
test>
suite>

3、运行 mvn clean test -Dtestng.xml