본문 바로가기
개발/VSCode

[VSCode] maven 프로젝트에서 Junit 추가

by Allonsy 2022. 1. 22.
반응형

이전에 VSCode에서 Java Test Runner 사용해서 테스트하는 방법을 포스팅했었다

근데 생각해보니까 초보개발자분들은 Junit 라이브러리를 추가하는 방법을 모를 수도 있겠단 생각이 들어서 급 포스팅!

https://allonsyit.tistory.com/24

 

[VSCode] JUnit 사용하기 / Test Report 창 다시 열기

https://code.visualstudio.com/docs/java/java-testing Java Unit Tests in Visual Studio Code See how you can test your Java code in Visual Studio Code. code.visualstudio.com VSCode에서 Java를 사용할때..

allonsyit.tistory.com

 

일단 JUnit을 사용하기 위해서는 해당 라이브러리가 필요하다

 

만약 현재 JUnit을 사용하려고 하는 프로젝트가 maven이나 gradle과 같은 빌드 툴을 사용하고 있다면 수월하다

# Maven

pom.xml 파일에 추가

JUnit4

<dependency>
  <groupId>junit</groupId>
  <artifactId>junit</artifactId>
  <version>(YOUR_JUNIT_VERSION)</version>
  <scope>test</scope>
</dependency>

JUnit5

	<dependencyManagement>
		<dependencies>
			<dependency>
				<groupId>org.junit</groupId>
				<artifactId>junit-bom</artifactId>
				<version>5.8.2</version>
				<type>pom</type>
				<scope>import</scope>
			</dependency>
		</dependencies>
	</dependencyManagement>

	<dependencies>
		<dependency>
			<groupId>org.junit.jupiter</groupId>
			<artifactId>junit-jupiter</artifactId>
			<scope>test</scope>
		</dependency>
	</dependencies>

 

 

[참고]

https://code.visualstudio.com/docs/java/java-testing#_junit-4

 

Java Unit Tests in Visual Studio Code

See how you can test your Java code in Visual Studio Code.

code.visualstudio.com

 

반응형

댓글