1
所以我有一個類:如何使用Spock測試單個類的記錄器?
ExtractJustAddedObjectTypeIDsBolt {
private static Logger logger = LoggerFactory.getLogger(ExtractJustAddedObjectTypeIDsBolt.class);
public void someMethod() {
logger.error("this is an error");
}
}
ClassOneTest extends Specification {
ExtractJustAddedObjectTypeIDsBolt bolt;
void setup() {
this.bolt = new ExtractJustAddedObjectTypeIDsBolt();
}
void cleanup() { // run after every feature method
}
def "test someMethod"() {
given:
when:
bolt.someMethod();
then:
bolt.logger.error("this is an error");
}
}
但是,這是我的錯誤:
199 [main] ERROR member.bolt.ExtractJustAddedObjectTypeIDsBolt - this is an error
Too few invocations for:
1 * bolt.logger.error("this is an error") (0 invocations)
Unmatched invocations (ordered by similarity):