Maven 按参数选择硒测试
我们使用SeleniumWebDriver构建了一些测试。使用JUnit注释,我们手动选择要运行的测试(@Test,@Ignore) 大概是这样的:Maven 按参数选择硒测试,maven,selenium,jenkins,junit,parameters,Maven,Selenium,Jenkins,Junit,Parameters,我们使用SeleniumWebDriver构建了一些测试。使用JUnit注释,我们手动选择要运行的测试(@Test,@Ignore) 大概是这样的: import org.junit.After; import org.junit.Before; import org.junit.Ignore; import org.junit.Test; import ... @RunWith(JUnit4.class) public class MainclassTest { @Test @I
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import ...
@RunWith(JUnit4.class)
public class MainclassTest {
@Test
@Ignore
public void Test01() {
...
}
@Test
// @Ignore
public void Test02() {
...
}
}
/** Marker for test case priority. * /
package priority;
public interface Low {
}
public interface Medium extends Low {
}
public interface High extends Medium {
}
上面我们只想运行Test02
但是现在我们想运行Jenkins的这个测试,并通过参数选择一个或多个测试,而不是注释掉@Ignore
。在Jenkins中,我们只提供POM文件和一些带有-dxxx
的参数
在不同的jenkins作业中运行不同测试组合的良好实践是什么?最好将测试分为不同的类?或者我可以在maven pom文件中更好地配置想要的测试吗?您可以使用
作为优先级的简单示例,声明接口并扩展如下层次结构:
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import ...
@RunWith(JUnit4.class)
public class MainclassTest {
@Test
@Ignore
public void Test01() {
...
}
@Test
// @Ignore
public void Test02() {
...
}
}
/** Marker for test case priority. * /
package priority;
public interface Low {
}
public interface Medium extends Low {
}
public interface High extends Medium {
}
然后根据需要对方法进行注释,例如:
public class MainclassTest {
@Test
@Category(priority.High.class)
public void Test01() {
...
}
@Test
@Category(priority.Low.class)
public void Test02() {
...
}
}
最后,使您的POM可配置
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<groups>${testcase.priority}</groups>
</configuration>
</plugin>
</plugins>
</build>
(注意,由于接口的扩展,Low将运行所有类别。如果不需要,只需删除扩展即可)。您可以使用
作为优先级的简单示例,声明接口并扩展如下层次结构:
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import ...
@RunWith(JUnit4.class)
public class MainclassTest {
@Test
@Ignore
public void Test01() {
...
}
@Test
// @Ignore
public void Test02() {
...
}
}
/** Marker for test case priority. * /
package priority;
public interface Low {
}
public interface Medium extends Low {
}
public interface High extends Medium {
}
然后根据需要对方法进行注释,例如:
public class MainclassTest {
@Test
@Category(priority.High.class)
public void Test01() {
...
}
@Test
@Category(priority.Low.class)
public void Test02() {
...
}
}
最后,使您的POM可配置
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<groups>${testcase.priority}</groups>
</configuration>
</plugin>
</plugins>
</build>
(注意,由于接口的扩展,Low将运行所有类别。如果您不希望这样,只需删除扩展)