Maven不考虑pom中定义的变量类别
我的Maven测试项目中有两个测试。我定义了两个类别作为接口,我以以下方式使用:@CategoryHighTest.class用于“testLR”方法和@CategoryMediumTest.class用于“testFD”方法。在我的项目中,我还将这两个接口定义为Maven不考虑pom中定义的变量类别,maven,testing,categories,Maven,Testing,Categories,我的Maven测试项目中有两个测试。我定义了两个类别作为接口,我以以下方式使用:@CategoryHighTest.class用于“testLR”方法和@CategoryMediumTest.class用于“testFD”方法。在我的项目中,我还将这两个接口定义为 package com.groups.project; public interface MediumTest { } 我想运行与单个类别匹配的测试方法。当使用mvn-Dtest.category=MediumTest te
package com.groups.project;
public interface MediumTest {
}
我想运行与单个类别匹配的测试方法。当使用mvn-Dtest.category=MediumTest test或mvn-Dtest.category=HighTest test从命令行按照特定类别运行这些测试时,所有测试方法都将运行testLR和testFD,而我只希望运行与我指定的类别相匹配的测试。
我甚至在MediumTest.class或MediumTest中更改了MediumTest,但它并没有改变任何东西,所有的测试都是运行的
在我看来,pom中的变量test.category似乎无法被jvm读取。
请参见我的Maven测试项目和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>com.open-projet</groupId>
<artifactId>open-android</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>open-android</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.13</version>
<configuration>
<groups>${test.category}</groups>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.37.0</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-server</artifactId>
<version>2.39.0</version>
</dependency>
</dependencies>
</project>
}您是否已经提供了团体课程的完整套餐?或者仅仅是类的名称?是的,尽管给出了完整的包,所有的测试方法都运行了,但我非常努力地尝试,最后终于找到了我的错误。我想和你分享。事实上,我刚刚清除了在测试类中定义的接口,以将这些我定义的接口保留在它们自己的文件中。现在一切都好了。
package com.groups.project;
import static org.junit.Assert.assertEquals;
import java.io.File;
import java.util.Collection;
import java.util.Arrays;
import java.util.List;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import com.google.common.io.Files;
/**
* @author selenese
*
*/
@RunWith(Parameterized.class)
public class getConnectFD {
private String quoiqui;
private String ou;
private WebDriver driver = null;
/**
* @throws java.lang.Exception
*/
@Parameters
public static Collection data(){
return Arrays.asList(new Object[][]{{"restaurant", "newyork"},});
}
public getConnectFD(String quoiqui, String ou){
super();
this.quoiqui = quoiqui;
this.ou = ou;
}
@Before
public void setUp() throws Exception {
driver = (WebDriver) SingleDriver.getInstance();
}
/**
* @throws java.lang.Exception
*/
@After
public void tearDown() throws Exception {
//driver.quit();
}
@Test
@Category(HighTest.class)
public void testLR() throws InterruptedException {
String item;
// Step 1
driver.get("http://m.opentour.fr/sprint3-p");
Thread.sleep(5000);
// Find the text input element by its name
WebElement quiquoiou = driver.findElement(By.xpath("//input[@name='activity']"));
quiquoiou.click();
WebElement input1 = null;
input1 = driver.findElement(By.xpath("//input[@id='globalActivity']"));
// Enter something to search for
input1.sendKeys(quoiqui);
input1.sendKeys(Keys.TAB);
AssertEquals("Trouver",driver.findElement(By.xpath("//button[@type='submit']")).
getText());
driver.findElement(By.xpath("//button[@type='submit']")).click();
Thread.sleep(3000);
}
@Test
@Category(MediumTest.class)
public void testFD() throws InterruptedException {
System.out.println("test");
}
public @interface HighTest {}
public @interface MediumTest {}