in Spring 5, I have class annotated as @Service, it reads a file and gets some data from it. The path of the file and some parameters are passed to private String variables annotated with @Value.
I want to extensively test this class. Can you tell me some Spring-way to do it or correct what I would do?
- I would inject not application.properties, but application-test1.properties using @ActiveProfile, but if I want to test 3-4 cases, do I need 3-4 .properties file?
- I would add to the service a constructor that accept the parameters I need, Spring IOC would use the standard no-args constructor, but in test I can use the other one, to pass all the values I want.
- DOes it work if I inject this property at runtime in the environment with System.getEnv()...
- Is it possible that putting @Value variables inside a Service could make it less testable? Maybe these value should be outside, in the class that use the Service and pass to it?
Whatever hint and explanation is well accepted to better understand the right approach (if there is one).
Aucun commentaire:
Enregistrer un commentaire