엔지니어로 가는 길

JUnit 4에서 JUnit 5로 마이그레이션하기 본문

private note/한 일, 할 일, 하고싶은 일

JUnit 4에서 JUnit 5로 마이그레이션하기

탐p슨 2022. 10. 26. 22:35
728x90

기존 프로젝트에서 사용하고 있던 라이브러리나 프레임워크의 버전을 바꾸는 것은 간단한 일이 아니다. 하지만 JUnit5로 마이그레이션 하는 것은 예외인 것 같다.

 

JUnit 4와 JUnit 5는 함께일 수 있다

 

https://junit.org/junit5/docs/current/user-guide/#migrating-from-junit4

 

JUnit 5 User Guide

Although the JUnit Jupiter programming model and extension model do not support JUnit 4 features such as Rules and Runners natively, it is not expected that source code maintainers will need to update all of their existing tests, test extensions, and custo

junit.org

 

... it is not expected that source code maintainers will need to update all of their existing tests, test extensions, and custom build test infrastructure to migrate to JUnit Jupiter.

...
having both JUnit 4 and JUnit Jupiter in the classpath does not lead to any conflicts. It is therefore safe to maintain existing JUnit 4 tests alongside JUnit Jupiter tests.

 

회사 프로젝트에 바로 JUnit 5 의존성을 추가한 뒤 기존 JUnit 4로 작성한 테스트를 실행해보았는데 모두 잘 동작했다. 특정 테스트를 하나 골라서 Jupiter를 사용하도록 테스트를 바꾼 뒤 실행해보았는데 JUnit 5로 잘 돌았다.

 

JUnit 5로 마이그레이션 해야하는 이유

 

https://www.baeldung.com/junit-5-migration

 

Migrating from JUnit 4 to JUnit 5 | Baeldung

Learn how to migrate from JUnit 4 to the latest JUnit 5 release - with an overview of the differences between the two versions.

www.baeldung.com

 

- JUnit 5, we get more granularity, and can import only what's necessary.
- JUnit 5 allows multiple runners to work simultaneously.
- JUnit 5 makes good use of the Java 8 features.

 

JUnit 5로 마이그레이션해야만 하는 압도적인 이유는 없지만 JUnit 5로의 마이그레이션이 어렵고 복잡하지 않기 때문에 JUnit 5로 굳이 마이그레이션 하지 않을 이유가 없다고 생각한다. 일단 JUnit 5 의존성을 추가하고 새로 작성하는 테스트는 JUnit 5로 작성하면서 기존 JUnit 4 테스트는 틈틈이 JUnit 5로 바꾸는 식으로 긴 호흡으로 천천히 마이그레이션해도 문제가 없기 때문이다.

728x90
Comments