오답노트

[JUnit] Service 테스트 본문

Java/Spring

[JUnit] Service 테스트

권멋져 2024. 5. 13. 22:37

소스코드

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.junit.jupiter.MockitoExtension;

@ExtendWith(MockitoExtension.class)
public class NaverSearchServiceImplTest {

    @InjectMocks
    private NaverSearchServiceImpl naverSearchService;

    @Test
    void testHarmornyroomSearch() {
        naverSearchService.getHarmornyRoom();
    }
}

테스트 코드

 

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;

import org.springframework.stereotype.Service;

@Service
public class NaverSearchServiceImpl implements NaverSearchService {

    @Override
    public void getHarmornyRoom(){
    	...
    }

}

서비스 구현체