Closed weiro-9-w7 closed 6 years ago
Hi @weiro-9-w7,
I will have a look as soon as I can. How urgent is the topic for you?
Cheers, Andreas
Hi @aaschmid , I'm glad you can give feedback to me in time. We prepare to use Junit-data-provider on the legacy systems . The function of different methods to use different annoation data is very important to us. So we hope to help solve it as soon as possible.
Hi @weiro-9-w7,
to be honest, I don't get your problem. Everything is working fine on my machine, see this screenshot:
Test should_return_array_when_is_array_is_true
got an array and the other didn't get one, as expected.
Is there another issue, I haven't understood yet?
Hi @aaschmid , yes, you can't get any problems because I move one method to other class. When one class have two methods and use annotation, issues will happen. Would you run test for DataProviderExternelFileMixTest. you will found problem.
Hi @weiro-9-w7,
problem is that the dataprovider results are cached per test class such that your dataprovider method is only called once for the first test case in this class. As JUnit4 always evaluates all test cases before executing it, it does not matter if you only execute one test case or all test cases in that class.
This caching mechanism was introduced by feature request, see #93. The caching, though, only occurs per test class in JUnit4. In JUnit5 the caching even occurs on per test run ...
I guess I should distinguish if a dataprovider takes a further argument (do not cache result) or not (cache result). Another possibility could be another setting option on @DataProvider
annotation.
I will try to provide a fix with a new version on the weekend.
Cheers, Andreas
@aaschmid thanks
Hi @weiro-9-w7,
I fixed the issue by introducing a cache
option on @DataProvider
, see commit 143948f (or above). I just need to stabilize the test cases (very fragile currently). You can test it manually by cloning the repo and creating your own version locally.
Any feedback welcome. Cheers, Andreas
Works with new version v2.2, see
Hi @aaschmid , verified, thanks!
Getting the below issue after using v2.2
java.lang.ArrayStoreException: sun.reflect.annotation.TypeNotPresentExceptionProxy
at sun.reflect.annotation.AnnotationParser.parseClassArray(Unknown Source)
at sun.reflect.annotation.AnnotationParser.parseArray(Unknown Source)
at sun.reflect.annotation.AnnotationParser.parseMemberValue(Unknown Source)
at java.lang.reflect.Method.getDefaultValue(Unknown Source)
at sun.reflect.annotation.AnnotationType.
@shiv20934: Can you provide more information and / or use v2.8 instead which might not have that issue anymore?
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 {
}
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())}}; } } }