So I have one class:
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");
}
}
But this is the error I get:
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):
Try with:
def "test someMethod"() {
given:
def logger = Mock(Logger)
and:
bolt.logger = logger
when:
bolt.someMethod()
then:
1 * logger.error("this is an error")
}
You need to mock first the Logger.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.