2016-10-02 18 views

回答

0

創建一個項目的jar,然後編輯/創建一個cron作業。在您的cron作業把類似的行:

0 2 * * * Java的罐子/路徑/到/你/ jar文件

這將在每天凌晨2點運行的腳本。

你可以看看下面的鏈接,如果你需要:

http://benr75.com/pages/using_crontab_mac_os_x_unix_linux

+0

我將如何確保它運行的TestNG的 –

+0

您如何運行你的測試用例的測試套件?從eclipse testng插件或從你的主要方法編程?如果你按照第二個選項,那麼只需創建一個jar並相應地完成你的工作。 –

+0

現在我正在通過eclipise運行它。 –

1

試試這個:

0 2 * * * cd ~/your_project_folder/ && mvn clean test 

你需要你的測試套件文件的testng.xml添加到您的Maven建立標籤(pom.xml)

<build> 
    <sourceDirectory>src</sourceDirectory> 
    <plugins> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-surefire-plugin</artifactId> 
      <version>${maven-surefire-version}</version> 
      <configuration> 
       <suiteXmlFiles> 
        <suiteXmlFile>${basedir}/testng.xml</suiteXmlFile> 
       </suiteXmlFiles> 
       <properties> 
        <property> 
         <name>usedefaultlisteners</name> 
         <value>true</value> 
        </property> 
       </properties> 
       <reportsDirectory>test-output/</reportsDirectory> 
       <testFailureIgnore>false</testFailureIgnore> 
      </configuration> 
     </build> 

上面的代碼片段將有助於運行你的testng.xml文件。

+0

它給編譯錯誤,如果我從eclipise編譯它,並顯示mvn命令沒有發現從命令行破壞它。我怎麼知道我的maven-apache安裝在哪裏? –

+0

如果您使用的是Mac,只需安裝「brew install maven」或運行「mvn」命令,如果您使用Windows下載maven並設置環境變量。 – Manidroid