반응형
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- JUnit
- java version
- LeetCode
- java
- No tests found for given includes
- java 버전 변경
- yum install java
- java 11
- property or field 'jobparameters' cannot be found on object of type
- java 여러개 버전
- easy
- springbatch error
- maybe not public or not valid?
- el1008e
- error
- parse
- OpenFeign
- no sources given
- log error
- Java 1.8
- AWS CLI
- aws
- xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools)
- Medium
- springboottest
- mac os git error
- querydsl no sources given
- java 1.8 11
- springboot
- 스프링부트테스트
Archives
- Today
- Total
쩨이엠 개발 블로그
[ JUnit ] JUnit Test 본문
728x90
반응형
SpringbootTest 어노테이션을 사용하다보면 굳이 서버를 올릴 필요 없이 간단하게 Test를 하고 싶을 때가 있다
예를 들면 정말 간단한 테스트코드 작성할 때
정말 Test만을 위한 프로젝트를 만들기로 한다
pom.xml
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13</version>
<scope>test</scope>
</dependency>
</dependencies>
package를 같이 해놔야 Test를 할 때 어려움이 없다
고 하지만 내 경우는 package도 default로 잡아놓았다 정말 자바코드를 위한 Test
import static org.junit.Assert.*;
import org.junit.Test;
public class ServiceTest {
@Test
public void example(){
String pattern = "01(0|1)-\\d{3,4}-\\d{4}";
assertTrue("010-8282-1234".matches(pattern));
assertTrue("010-828-1234".matches(pattern));
assertFalse("011-12-1234".matches(pattern));
}
@Test
public void example1(){
String pattern = "ab";
String str = "abcabcdabcde";
System.out.println(str.replaceAll(pattern, "*"));
}
}
static으로 import를 해놓으면 assertTrue, assertFalse등을 바로 사용할 수 있다
테스트를 돌리면 Test 어노테이션이 붙은 함수명이 보인다
끝 -
728x90
반응형
'개발 > Spring' 카테고리의 다른 글
[ SpringBootTest ] No tests found for given includes: [ApplicationTests.main](filter.includeTestsMatching) (0) | 2022.05.06 |
---|---|
[ Swagger ] @Schema LocalDateTime Format (2) | 2022.04.06 |
[ Redis ] Redis 환경 간단하게 구축하기 (0) | 2020.09.16 |
[ Spring boot] Could not resolve all files for configuration compileClasspath (0) | 2020.08.24 |
Maven pom to gradle (0) | 2020.07.13 |
Comments