skrape{it}
1.1.X
1.1.X
  • Introduction
  • Why it exists
  • overview
    • Setup
    • Who should be using it
  • Http Client
    • Overview
    • Fetchers
      • HttpFetcher
      • BrowserFetcher
      • AsyncFetcher
      • Implement your own
    • Request Options
    • Pre-configure client
    • Response
      • Status
      • Cookies
  • Html Parser
    • Parsing HTML
  • assertions
    • expect content
  • How to Use
    • Testing
    • Scraping
    • JS-rendered sites
  • Examples
    • Grab all links from a Website
    • Creating a RESTful API (Spring-Boot)
  • GitHub Repo
  • Extensions
    • MockMvc
      • Getting Started
      • GitHub Repo
    • Ktor
      • Getting Started
      • GitHub Repo
  • About skrape{it}
Powered by GitBook
On this page
  • Setup
  • How to Use

Was this helpful?

  1. Extensions

MockMvc

An Extension for Spring MockMvc tests to enable meaningful testing of controllers that produces HTML.

PreviousCreating a RESTful API (Spring-Boot)NextGetting Started

Last updated 6 years ago

Was this helpful?

Setup

In order to use the MockMvc-extension it's required to have the artifact in the classpath as well as having a proper spring-test / spring-boot-test setup.

pom.xml
<dependency>
   <groupId>it.skrape</groupId>
   <artifactId>skrapeit-core</artifactId>
   <version>LATEST</version>
   <scope>test</scope>
</dependency>
<dependency>
   <groupId>it.skrape</groupId>
   <artifactId>skrapeit-mockmvc</artifactId>
   <version>LATEST</version>
   <scope>test</scope>
</dependency>
build.gradle.kts
testCompile("it.skrape:skrapeit-core:+")
testCompile("it.skrape:skrapeit-mockmvc:+")

How to Use

The MockMvc-extension will extend MockMvc's ResultActions with an andExpectHtml{} lambda function. The scope of the lambda will give you a parsed response body (deserialized to a Doc) and enables you to make comfortable assumptions about the content, properties and structure of the document.

skrape{it}
skrapeit-core
Documentation by example