> For the complete documentation index, see [llms.txt](https://jack80342.gitbook.io/spring-boot/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://jack80342.gitbook.io/spring-boot/iv.-spring-boot-features/46.-creating-your-own-auto-configuration/46.4-testing-your-auto-configuration/46.4.2-overriding-the-classpath.md).

# 46.4.2 覆盖类路径

测试当一个特殊的类或者包在运行时不存在的时候会发生什么也是可能的。Spring Boot提供了`FilteredClassLoader`。runner可以容易的使用它。在下面的例子里，我们断言如果`UserService`不存在，自动配置会正确地禁用：

```java
@Test
public void serviceIsIgnoredIfLibraryIsNotPresent() {
    this.contextRunner.withClassLoader(new FilteredClassLoader(UserService.class))
            .run((context) -> assertThat(context).doesNotHaveBean("userService"));
}
```
