Hello , would you help to check the issue.
I write a sample in https://github.com/weiro-9-w7/junit-data-provider
when you DataProviderExternelFileTest testcase, FrameworkMethod get annotation is the other method annotation.
@RunWith(DataProviderRunner.class)
public class DataProviderExternelFileTest {
@Test
@UseDataProvider(value = "loadFromExternalFile", location = LoadFromExternalFile.class)
@ExternalFile(format = ExternalFile.Format.JSON, value = "persons.json", clazz=Person.class, isArray=true)
public void should_return_array_when_is_array_is_true(List<Person> person) {
// Expect:
assertEquals(person.get(0).getName(), "zhangsan");
assertEquals(person.get(0).getAge(), 18);
}
@Test
@UseDataProvider(value = "loadFromExternalFile", location = LoadFromExternalFile.class)
@ExternalFile(format = ExternalFile.Format.JSON, value = "person.json", clazz=Person.class)
public void should_return_object_when_is_array_is_false(Person person) {
// Expect:
assertEquals(person.getName(), "zhangsan");
assertEquals(person.getAge(), 18);
}
}
public class LoadFromExternalFile {
@DataProvider
public static Object[][] loadFromExternalFile(FrameworkMethod testMethod) throws IOException {
ExternalFile externalFile = testMethod.getAnnotation(ExternalFile.class);
String testDataFile = externalFile.value();
File file = new File(LoadFromExternalFile.class.getResource("/").getPath() + testDataFile);
String content = FileUtils.readFileToString(file, "utf8");
if(externalFile.isArray()){
return new Object[][]{{JSON.parseArray(content, externalFile.clazz())}};
}else{
return new Object[][]{{JSON.parseObject(content, externalFile.clazz())}};
}
}
}
when you run should_return_array_when_is_array_is_true method, but ExternalFile externalFile = testMethod.getAnnotation(ExternalFile.class); externalFile is should_return_object_when_is_array_is_false
type: enhancement resolution: fixed component: junit4 component: junit-jupiter component: junit-jupiter-params