I have a query about using parameterized tests for my unit testing of my APIs. Now instead of building an arraylist like
Arrays.asList(new Object[]{
{1},
In Spring-boot Java framework, you can use the Value
annotation conveniently within the class,
@Component
public class MyRunner implements CommandLineRunner {
@Value("classpath:thermopylae.txt") //Annotation
private Resource res; // res will hold that value the `txt` player
@Autowired
private CountWords countWords;
@Override
public void run(String... args) throws Exception {
Map words = countWords.getWordsCount(res);
for (String key : words.keySet()) {
System.out.println(key + ": " + words.get(key));
}
}
}
Source