此内容没有您所选择的语言版本。
Chapter 4. Testing your Eclipse Vert.x application with JUnit
After you build your Eclipse Vert.x application in the getting-started project, test your application with the JUnit 5 framework to ensure that it runs as expected. The following two dependencies in the Eclipse Vert.x pom.xml file are used for JUnit 5 testing:
-
The
vertx-junit5dependency is required for testing. JUnit 5 provides various annotations, such as,@Test,@BeforeEach,@DisplayName, and so on which are used to request asynchronous injection ofVertxandVertxTestContextinstances. -
The
junit-jupiter-enginedependency is required for execution of tests at runtime.
Prerequisites
-
You have built the Eclipse Vert.x
getting-startedproject using thepom.xmlfile.
Procedure
Open the generated
pom.xmlfile and set the version of the Surefire Maven plug-in:<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-surefire-plugin</artifactId> <version>3.0.0-M5</version> </plugin>Copy to Clipboard Copied! Toggle word wrap Toggle overflow Create a directory structure
src/test/java/com/example/in the root directory, and navigate to it.mkdir -p src/test/java/com/example/ cd src/test/java/com/example/
$ mkdir -p src/test/java/com/example/ $ cd src/test/java/com/example/Copy to Clipboard Copied! Toggle word wrap Toggle overflow Create a Java class file
MyTestApp.javacontaining the application code.Copy to Clipboard Copied! Toggle word wrap Toggle overflow To run the JUnit test on my application using Maven run the following command from the root directory of the application.
mvn clean verify
mvn clean verifyCopy to Clipboard Copied! Toggle word wrap Toggle overflow You can check the test results in the
target/surefire-reports. Thecom.example.MyAppTest.txtfile contains the test results.