Junit parameterized tests using file input

后端 未结 3 1669
渐次进展
渐次进展 2021-01-06 05:10

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},         


        
3条回答
  •  广开言路
    2021-01-06 05:35

    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

提交回复
热议问题