Java – inject mock @ service for spring unit test

I'm testing a class that uses @ Autowired injection service:

public class RuleIdValidator implements ConstraintValidator<ValidRuleId,String> {

    @Autowired
    private RuleStore ruleStore;

    // Some other methods
}

However, how to simulate the rule base during testing? I don't know how to inject my simulated rulestore into spring and enter the automatic cabling system

thank you

Solution

You can use something like mockito to simulate the rule base returned during testing This stack overflow article has a good example:

spring 3 autowiring and junit testing

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>