测试用例编写指南以及最佳实践 - Maven
Maven 是一个 Java自动化构建框架,我们可以使用 junit 作为测试框架。本文档展示了如何在 Testany 中编写 Maven 测试用例。
Testany 测试用例支持的 Java 版本是 JDK 11
如果需要任何新的 JDK 版本,请随时联系我们的客户支持
测试用例包 - 一个 zip 文件
目前我们仅支持将本地 zip 文件上传到 Testany,zip 文件至少需要包含一个文件:
测试用例代码文件或文件,如
StringTest.java
,pom.xml
StringTest.javaJAVApackage hello.maven; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.*; class StringTest { @Test void runMavenTests() { String testStr = System.getenv("TEST_STR"); assertEquals("FOO", testStr); } }
pom.xml
XML<?xml version="1.0" encoding="UTF-8"?> <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>hello.maven</groupId> <artifactId>hello-maven</artifactId> <version>1.0</version> <properties> <java.version>11</java.version> <junit-jupiter.version>5.7.2</junit-jupiter.version> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <dependencies> <!-- junit 5 --> <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter-engine</artifactId> <version>${junit-jupiter.version}</version> <scope>test</scope> </dependency> </dependencies> <build> <plugins> <!-- Need at least 2.22.0 to support JUnit 5 --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>3.0.0-M5</version> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.8.1</version> <configuration> <source>11</source> <target>11</target> </configuration> </plugin> </plugins> </build> </project>
将所有相关文件压缩为一个 zip 文件,在这种情况下,测试用例包文件是

在成功准备好 .zip
文件后,您将能够在 Testany 平台上注册您的测试用例。请参阅 《管理测试用例》 以获取注册的分步指南。