2016-09-14 190 views
1

我是Maven的新手,試圖用同樣的方法執行一個Appium測試用例。當我執行mvn test命令時,測試不會被執行。請在下面瞭解更多詳情。Maven的測試運行

下面是Java代碼:

package Test; 

import java.net.MalformedURLException; 

import java.net.URL; 

import java.util.concurrent.TimeUnit; 

import org.openqa.selenium.remote.DesiredCapabilities; 

import io.appium.java_client.android.AndroidDriver; 

import io.appium.java_client.remote.MobileCapabilityType; 

import io.appium.java_client.remote.MobilePlatform; 

/** 

* Unit test for simple App 

*/ 

public class AppTest 

{ 

public void test() throws MalformedURLException 

{ 

DesiredCapabilities cap=new DesiredCapabilities(); 

cap.setCapability(MobileCapabilityType.PLATFORM_NAME, MobilePlatform.ANDROID); 

cap.setCapability(MobileCapabilityType.DEVICE_NAME, "Android device"); 

cap.setCapability(MobileCapabilityType.BROWSER_NAME, "Chrome"); 

AndroidDriver driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"),cap); 

driver.manage().timeouts().implicitlyWait(25, TimeUnit.SECONDS); 

driver.get("http://www.google.com"); 

} 

} 

MVN測試輸出:

[INFO] Scanning for projects... 
[INFO]                   
[INFO] ------------------------------------------------------------------------ 
[INFO] Building Test 1.0-SNAPSHOT 
[INFO] ------------------------------------------------------------------------ 
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ Test --- 
[INFO] Using 'UTF-8' encoding to copy filtered resources. 
[INFO] skip non existing resourceDirectory /Users/gowtham/Desktop/Projects/Test/src/main/resources 
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ Test --- 
[INFO] Nothing to compile - all classes are up to date 
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ Test --- 
[INFO] Using 'UTF-8' encoding to copy filtered resources. 
[INFO] skip non existing resourceDirectory /Users/gowtham/Desktop/Projects/Test/src/test/resources 
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ Test --- 
[INFO] Changes detected - recompiling the module! 
[INFO] Compiling 1 source file to /Users/gowtham/Desktop/Projects/Test/target/test-classes 
[INFO] 
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ Test --- 
[INFO] Surefire report directory: /Users/gowtham/Desktop/Projects/Test/target/surefire-reports 

------------------------------------------------------- 
T E S T S 
------------------------------------------------------- 
Running Test.AppTest 
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.001 sec 

Results : 

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

[INFO] ------------------------------------------------------------------------ 
[INFO] BUILD SUCCESS 
[INFO] ------------------------------------------------------------------------ 
[INFO] Total time: 2.092 s 
[INFO] Finished at: 2016-09-14T14:34:17-07:00 
[INFO] Final Memory: 20M/252M 
[INFO] ------------------------------------------------------------------------ 

POM

<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.0</modelVersion> 

     <groupId>Test</groupId> 

     <artifactId>Tests</artifactId> 

     <version>1.0-SNAPSHOT</version> 

     <packaging>jar</packaging> 

     <name>Test</name> 

     <url>http://maven.apache.org</url> 

     <properties> 

     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 

     </properties> 

     <dependencies> 

     <dependency> 

     <groupId>io.appium</groupId> 

     <artifactId>java-client</artifactId> 

     <version>4.1.2</version> 

    </dependency> 

    <dependency> 

     <groupId>org.seleniumhq.selenium</groupId> 

     <artifactId>selenium-java</artifactId> 

     <version>2.53.1</version> 

    </dependency> 

     <dependency> 

      <groupId>junit</groupId> 

      <artifactId>junit</artifactId> 

      <version>3.8.1</version> 

      <scope>test</scope> 

     </dependency> 

    </dependencies> 

    </project> 
+0

對Appium不太確定,但是您是否試圖用@Test註釋測試方法?我在這裏找到了一些例子https://github.com/appium/sample-code/blob/master/sample-code/examples/java/junit/src/test/java/com/saucelabs/appium/SimpleTest.java和那裏是那些註釋,所以也許嘗試。 – Shadov

+0

是的,我試着用@Test註解但沒有運氣。 – gowthamjs23

回答

0

你在你的依賴有JUnit版本3。 JUnit 3不支持不擴展TestCase的測試,而您的測試不支持。要麼擴展TestCase,要麼將JUnit版本更改爲4.11

JUnit 3和4之間的主要差異列在this answer中。

+0

通過使用擴展TestCase解決了問題。謝謝! – gowthamjs23