2013-08-21 144 views
0

在使用从行家运行我的测试情况如下命令如何从命令行使用maven运行selenium testNG测试用例?

c:\> mvn test 

我得到以下结果:

D:\arpit_maven\mavenProject\build_demo>mvn test 
[INFO] Scanning for projects... 
[INFO] 
[INFO] ------------------------------------------------------------------------ 
[INFO] Building build_demo 1.0-SNAPSHOT 
[INFO] ------------------------------------------------------------------------ 
[INFO] 
[INFO] --- maven-resources-plugin:2.5:resources (default-resources) @ build_demo 
--- 
[debug] execute contextualize 
[INFO] Using 'UTF-8' encoding to copy filtered resources. 
[INFO] skip non existing resourceDirectory D:\arpit_maven\mavenProject\build_dem 
o\src\test\resources 
[INFO] 
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ build_demo -- 
- 
[INFO] Nothing to compile - all classes are up to date 
[INFO] 
[INFO] --- maven-resources-plugin:2.5:testResources (default-testResources) @ bu 
ild_demo --- 
[debug] execute contextualize 
[INFO] Using 'UTF-8' encoding to copy filtered resources. 
[INFO] skip non existing resourceDirectory D:\arpit_maven\mavenProject\build_dem 
o\src\test\resources 
[INFO] 
[INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) @ build 
_demo --- 
[INFO] Nothing to compile - all classes are up to date 
[INFO] 
[INFO] --- maven-surefire-plugin:2.10:test (default-test) @ build_demo --- 
[INFO] Surefire report directory: D:\arpit_maven\mavenProject\build_demo\target\ 
surefire-reports 

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

Results : 

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

[INFO] ------------------------------------------------------------------------ 
[INFO] BUILD SUCCESS 
[INFO] ------------------------------------------------------------------------ 
[INFO] Total time: 3.031s 
[INFO] Finished at: Thu Mar 21 10:29:17 IST 2013 
[INFO] Final Memory: 5M/15M 
[INFO] ------------------------------------------------------------------------ 
D:\arpit_maven\mavenProject\build_demo> 

我的pom.xml如下。请让我知道如果pom.xml中缺少任何东西。 我的测试用例位于src \ test \ java \文件夹中。

<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/maven-v4_0_0.xsd"> 
<modelVersion>4.0.0</modelVersion> 
<groupId>demo1</groupId> 
<artifactId>build_demo</artifactId> 
<packaging>jar</packaging> 
<version>1.0-SNAPSHOT</version> 
<name>build_demo</name> 
<url>http://maven.apache.org</url> 
<properties> 
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
</properties> 

<dependencies> 

<dependency> 
     <groupId>org.seleniumhq.selenium</groupId> 
     <artifactId>selenium-java</artifactId> 
     <version>2.33.0</version> 

    </dependency> 

<dependency> 
    <groupId>junit</groupId> 
    <artifactId>junit</artifactId> 
    <version>3.8.1</version> 
    <scope>test</scope> 
</dependency> 
<dependency> 
<groupId>org.testng</groupId> 
<artifactId>testng</artifactId> 
<version>6.8.1</version> 
<scope>test</scope> 
</dependency> 
<dependency> 
     <groupId>org.apache.poi</groupId> 
     <artifactId>poi</artifactId> 
     <version>3.8</version> 
    </dependency> 
</dependencies> 
<build> 
    <resources> 
     <resource> 
      <directory>src/test/resources</directory> 
      <filtering>true</filtering> 
     </resource> 
    </resources> 
    <plugins> 
    <plugin> 
    <groupId>org.apache.mavan.plugins</groupId> 
    <artifactId>mavan-compiler-plugin</artifactId> 
    <version>2.3.2</version> 
    <configuration> 
    <source>1.6</source> 
    <target>1.6</target> 
    </configuration> 
    </plugin> 
    </plugins> 
    </build> 
    <profiles> 
    <profile> 
     <id>selenium-tests</id> 
     <build> 
      <plugins> 
       <plugin> 
        <groupId>org.apache.maven.plugins</groupId> 
        <artifactId>maven-surefire-plugin</artifactId> 
        <version>2.4.3</version> 
        <configuration> 
         <includes> 
          <include>Opencart.java</include> 
         </includes> 
        </configuration> 
       </plugin> 
      </plugins> 
     </build> 
    </profile> 
</profiles> 
</project> 
+0

您是否已将相应的测试命名为surefire规则?像* Test.java,Test * .java等。除此之外,您正在运行应该由maven-failsafe-plugin运行的集成测试。 – khmarbaise

+1

我的测试用例文件名是Opencart.java。我是否应该将其更改为OpencartTest.java – Arpitk12

+0

是的,您必须通过maven运行它,否则maven-surefire-plugin的命名约定是您应该遵循的命名约定。但正如我之前提到的,您正在运行集成测试,因此它们应该被命名为OpencartIT.java,而您必须配置maven-failsafe-plugin! – khmarbaise

回答

2

将您的类重命名为OpencartTest.java或者在surefire中更改过滤器属性,以便它获取Opencart.java类。您还可以创建套件xml文件,其中包括Opencart.java。

就我个人而言,我只是改变你的班级的名字!

+0

它通过更改类的名称来工作 – Arpitk12

相关问题