Java – inject mock @ service for spring unit test
•
Java
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
二维码