我有main
类,看起来像这样
@SuppressWarnings("checkstyle:hideutilityclassconstructor") // FIXME:doesn't work
@ComponentScan({"com.lapots.breed.judge"})
@SpringBootApplication
public class JudgeRuleEngineApplication {
public static void main(final String[] args) {
SpringApplication.run(JudgeRuleEngineApplication.class, args);
}
@Bean
public CommandLineRunner initCache(final InMemoryPlayerLevelCache cache) {
return args -> {
cache.put(1, 100);
cache.put(2, 1000);
cache.put(3, 10000);
cache.put(4, 100000);
};
}
}
启动时,我使用值初始化cache
。
但是在测试期间我想阻止它 - 我想从执行中排除commandlinerunner
我的测试看起来像这样
@WebFluxTest(excludeFilters =
@ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, value = CommandLineRunner.class))
class InMemoryPlayerLevelCacheTestSpec extends Specification {
@Autowired
InMemoryPlayerLevelCache cache
def "should access cache"() {
when:
cache.put(10, 200)
then:
1 == cache.size()
200 == cache.get(10)
}
}
我尝试使用excludeFilter
排除它但仍然我的测试失败,因为它有比预期更多的元素(应该有1但在测试+4初始化时它有5为1)。
有什么问题?