Article Directory
Both maven and JUnit can debug java projects.
This article describes the debugging steps using these two methods:
maven
New maven project
The new version of Eclipse comes with maven, so just create it yourself.
Eclipse -> File -> New -> Other -> maven project
group id: fill in the organization name
artifact id: project name
Modify pom.xml
After creating maven, I often encounter some problems, such as "maven no longer supports source option 1.5" or "using junit in maven to prompt that the junit package cannot be found", as well as the slow download of maven on the original website and the configuration of mirroring.
At this time, some settings must be made to pom and xml, as follows:
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<modelVersion>4.0.0</modelVersion>
<groupId>yourgroupId</groupId>
<artifactId>yourartifactId</artifactId>
<version>0.0.1-SNAPSHOT</version>
<repositories>
<repository>
<id>central</id>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
</pluginRepository>
</pluginRepositories>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.7</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
JUnit
Import JUnit
When importing packages in JUnit, sometimes eclipse will report an error. At this time, we need to import JUnit into our project: the
steps are as shown in the figure above, select JUnit in Add Libraries and import it. Then you can use JUnit.
Code placement
After creating a new maven project, our class code is placed under src/main/java, and the test code is placed under src/test/java.
test
Right-click the project and select run as:
To use JUnit, click JUnit.
To use Maven, click Maven Test.
The effect is as follows: