如何在junit中参数化dataProvider?

时间:2019-05-01 10:46:49

标签: java junit testng-dataprovider

我有一个使用DataProvider的有效JUnit测试类,实际上是从目录中的文件读取测试的。测试采用“模拟DB”实施方式,其中有5个文件通过DB接口加载到内存中并由服务器提供服务,还有一个文件是“数据提供者”(带有输入和预期输出的csv)。

export class CountryService {

  constructor(private http: HttpClient) { }

  getUsers() {
    return this.http.get('https://jsonplaceholder.typicode.com/users');
  }
}

我希望将其更改为可以在子目录中添加新测试的方式。

filterCountryMultiple(event) {
    this.userService.getUsers().subscribe(
      (val: any[]) => {
        this.filteredUsersMultiple = val.map(user => user.username);
        console.log(this.filteredUsersMultiple);
      }
    )
  }

它的工作方式应是将模拟数据库加载到一个子目录中,然后从同一个子目录中运行测试,然后重置所有内容并对下一个子目录执行相同的操作。

我所拥有的(在注释中,我添加了一些与“ subDir”相关的东西,但不确定如何在不手动复制并粘贴每个子目录的提供者和测试方法的情况下使用它们):

tests/table1.csv
..
tests/table5.csv
tests/data-provider.csv

0 个答案:

没有答案
相关问题