스프링 부트 개념과 활용
4. 스프링 부트 활용
포스팅 참조 정보
GitHub
공부한 내용은 GitHub에 공부용 Organizations에 정리 하고 있습니다
해당 포스팅에 대한 내용의 GitHub 주소
실습 내용이나 자세한 소스코드는 GitHub에 있습니다
포스팅 내용은 간략하게 추린 핵심 내용만 포스팅되어 있습니다
https://github.com/freespringlecture/springboot-concept-uses/tree/chap04-09-08-mvc-htmlunit
freespringlecture/springboot-concept-uses
백기선님의 스프링 부트 개념과 활용 강의 내용 정리. Contribute to freespringlecture/springboot-concept-uses development by creating an account on GitHub.
github.com
해당 포스팅 참고 인프런 강의
https://www.inflearn.com/course/%EC%8A%A4%ED%94%84%EB%A7%81%EB%B6%80%ED%8A%B8/dashboard
스프링 부트 개념과 활용 - 인프런
스프링 부트의 원리 및 여러 기능을 코딩을 통해 쉽게 이해하고 보다 적극적으로 사용할 수 있는 방법을 학습합니다. 중급 프레임워크 및 라이브러리 Spring Spring Boot 온라인 강의
www.inflearn.com
실습 환경
- Java Version: Java 11
- SpringBoot Version: 2.1.2.RELEASE
9. 스프링 웹 MVC 8부: HtmlUnit
HTML 템플릿 뷰 테스트를 보다 전문적으로 하자
HTML을 단위테스트 하기 위한 Tool
HtmlUnit – Getting Started with HtmlUnit
Introduction The dependencies page lists all the jars that you will need to have in your classpath. The class com.gargoylesoftware.htmlunit.WebClient is the main starting point. This simulates a web browser and will be used to execute all of the tests. Mos
htmlunit.sourceforge.net
의존성추가
scope이 test이므로 test할때만 사용함
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>htmlunit-driver</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.sourceforge.htmlunit</groupId>
<artifactId>htmlunit</artifactId>
<scope>test</scope>
</dependency>
테스트 가능한 기능
- Form submit
- 특정 브라우저인척 하기
- 특정 문서의 엘리먼트를 가져와서 값을 비교하거나 할수있음
테스트 코드
@RunWith(SpringRunner.class)
@WebMvcTest(SampleController.class)
public class SampleControllerTest {
@Autowired
WebClient webClient;
@Test
public void hello() throws Exception {
HtmlPage page = webClient.getPage("/hello"); // /hello 로 요청시
HtmlHeading1 h1 = page.getFirstByXPath("//h1"); //h1 제일 앞에있는 것 하나만 가져옴
assertThat(h1.getTextContent()).isEqualToIgnoringCase("ironman"); // 대소문자인것을 무시하고 문자열이 같은지 비교
}
}
'개발강의정리 > Spring' 카테고리의 다른 글
[스프링 부트 개념과 활용] 4-9. 스프링 웹 MVC 10부: Spring HATEOAS (0) | 2019.11.14 |
---|---|
[스프링 부트 개념과 활용] 4-9. 스프링 웹 MVC 9부: ExceptionHandler (0) | 2019.11.13 |
[스프링 부트 개념과 활용] 4-9. 스프링 웹 MVC 7부: Thymeleaf (0) | 2019.11.11 |
[스프링 부트 개념과 활용] 4-9. 스프링 웹 MVC 6부: index 페이지와 파비콘 (0) | 2019.11.10 |
[스프링 부트 개념과 활용] 4-9. 스프링 웹 MVC 5부: 웹JAR (0) | 2019.11.09 |
댓글