스프링 부트와 AWS로 혼자 구현하는 웹 서비스 03
오류가 어떻게 해도 해결이 되지 않아서, 이렇게 저렇게 구글링을 해보던 와중에 책에 나와있는 사진들과 내 화면이
프로젝트 생성페이지(generator)부터 다른 이유가 버전차이 때문이라는걸 알게 되었음
혹시나, spring initializr에서 만들어온 프로젝트때문에 다양한 오류들이 생기는걸까 싶어서 기본 페이지에서 프로젝트를 만들어보기로 함

=> 이게 예전화면(책에 예시로 보여져있는 화면)

=> 이게 최신 버전의 화면
첫날에 프로젝트를 만들때, 그룹 ID도, 아티팩트 ID도 보이지 않아서 굉장히 당황했었는데..
고급 설정을 들어가니 다 보임..!
깃허브에 올려두신 build.gradle 의 jdk 버전이 17이여서 , 이번에는 그걸 받아서 사용하기로 했음

다 작성한 후에 적용을 하니, 의존성들이 잘 받아진 것을 볼 수 있었음
몇일간 작업을 해보니, 오류도 많이 뜨고, 많이 삭제 하고, 생성하고 하는등 바뀌는게 많아서.. 일단 git에 연동은 잠시 미뤄두기로 했음


run메서드를 찾을 수없다고 symbol 에러가 또 뜨기도 했지만

코드를 잘 뜯어보다가, import 한부분을 보고 혹시나 싶어서 함수코드를 바꿨더니, 오류가 사라짐

이번에도 어김없이 junit오류가 떴음
구글링 ~~
책에 쓰여있는 junit의 버전이 4이길래
implementation 'junit:junit:4.13.1'
이걸 build.gradle에 추가해주었음
==> 5로 넘어오면서 바뀐부분들이 좀 있던데, 그런부분을 잘 찾아가면서 해야할듯
RunWith -> ExtendWith로 바뀌었다거나 하는 부분 말이다
물론 책에는 RunWith로 나와있음

빨간색 오류가 뜨던 것이 사라졌음
그리고 나서 테스트를 돌려보니

다른 오류가 생겼음
구글링을 해보니, 경로 오류라고 get으로 값을 받아와야하는데, 못받아와서 생기는 오류라고 함
보통은 오타에 의해서 발생하던데, 나는 책이랑 똑같이 써서 오류는 없었음
package com.start.khw.springboot.web;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController //1
public class HelloController {
@GetMapping("/hello") //2
public String hello() {
return "hello";
}
}
HelloController
package com.start.khw.springboot.web;
import org.junit.Test;
//import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@RunWith(SpringRunner.class) //1
@WebMvcTest(controllers = HelloControllerTest.class) //2
public class HelloControllerTest{
@Autowired //3
private MockMvc mvc;
@Test
public void hello_is_returned() throws Exception{
String hello = "hello";
this.mvc.perform(get("/hello")) //5
.andExpect(status().isOk()) //6
.andExpect(content().string(hello));
}
}
HelloControllerTest
혹시 몰라서 Application으로 들어가서 실행을 시켜봤음
package com.start.khw.springboot;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}

책에 나온거처럼, 글씨가 잘 표현이 됨...? -> 앱이 잘 돌아감

확인을 해보면, 여기서도 응답이 잘 돌아오는것을 볼 수 있는데, 테스트는 왜그러지...

아무 문자나 되는게 아닌게 맞아 보이는데 음 ..
===> 앱 자체에는 문제가 없다 -> 테스트를 구현하는 클래스/함수에서 문제가 있다.