Another code snippet to run Java JUnit quickly from the command line:
(Assuming you have download Java SDK, and add JAVA_HOME to your PATH variable)
1. You have downloaded the Maven binary zip and extracted it to your local folder e.g Program files
2. Add the `bin` folder of the Maven folder to your PATH
3. Create a project folder called this `Testing`
4. Inside "Testing" folder, create two folders, one for your Java code files and another for your Test files. For the Java files folder, create `src\main\java`. for testing files create `src\test\java`. By putting the files inside the `java` folder, the test files can use the Java classes without using any import, and both will be on the default namespace.
5. put pom.xml inside "Testing" folder, the pomxl should import the Junit
<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.example</groupId>
<artifactId>my-project</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<!-- JUnit 5 Dependencies -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.7.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.7.0</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<!-- Maven Surefire Plugin for running tests -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<includes>
<include>**/*Test.java</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
</project>
5. Open the command line or terminal in the "Testing" folder, and run "mvn test"
No comments:
Post a Comment