Skip to content

io microsphere spring test util ServletTestUtils

github-actions[bot] edited this page Jun 18, 2026 · 18 revisions

ServletTestUtils

Type: Class | Module: microsphere-spring-test | Package: io.microsphere.spring.test.util | Since: 1.0.0

Source: microsphere-spring-test/src/main/java/io/microsphere/spring/test/util/ServletTestUtils.java

Overview

The utility class for Servlet Testing

Declaration

public abstract class ServletTestUtils

Author: Mercy

Version Information

  • Introduced in: 1.0.0
  • Current Project Version: 0.2.27-SNAPSHOT

Version Compatibility

This component is tested and compatible with the following Java versions:

Java Version Status
Java 17 ✅ Compatible
Java 21 ✅ Compatible
Java 25 ✅ Compatible

Examples

Method Examples

addTestServlet

ServletContext servletContext = ...; // Obtain the ServletContext
ServletTestUtils.addTestServlet(servletContext);

addTestFilter

ServletContext servletContext = ...; // Obtain the ServletContext
ServletTestUtils.addTestFilter(servletContext);

Usage

Maven Dependency

Add the following dependency to your pom.xml:

<dependency>
    <groupId>io.github.microsphere-projects</groupId>
    <artifactId>microsphere-spring-test</artifactId>
    <version>${microsphere-spring.version}</version>
</dependency>

Tip: Use the BOM (microsphere-spring-dependencies) for consistent version management. See the Getting Started guide.

Import

import io.microsphere.spring.test.util.ServletTestUtils;

API Reference

Public Methods

Method Description
addTestServlet Adds a test servlet to the provided ServletContext.
addTestFilter Adds a test filter to the provided ServletContext.

Method Details

addTestServlet

public static ServletRegistration.Dynamic addTestServlet(ServletContext servletContext)

Adds a test servlet to the provided ServletContext.

This method registers a TestServlet with the default servlet name TestServlet#DEFAULT_SERVLET_NAME and maps it to the default URL pattern TestServlet#DEFAULT_SERVLET_URL_PATTERN.

Example Usage

`ServletContext servletContext = ...; // Obtain the ServletContext
ServletTestUtils.addTestServlet(servletContext);
`

addTestFilter

public static FilterRegistration.Dynamic addTestFilter(ServletContext servletContext)

Adds a test filter to the provided ServletContext.

This method registers a TestFilter with the default filter name TestFilter#DEFAULT_FILTER_NAME and maps it to the default URL pattern TestFilter#DEFAULT_FILTER_URL_PATTERN. Additionally, it adds a test servlet to ensure the filter can be mapped to it.

Example Usage

`ServletContext servletContext = ...; // Obtain the ServletContext
ServletTestUtils.addTestFilter(servletContext);
`

See Also

  • ServletContext

This documentation was auto-generated from the source code of microsphere-spring.

Home

spring-context

spring-guice

spring-jdbc

spring-test

spring-web

spring-webflux

spring-webmvc

Clone this wiki locally