-
Notifications
You must be signed in to change notification settings - Fork 163
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dataprovider caches results even for dynamically created data / results (e.g. using test method as parameter) #105
Comments
com.tngtech.junit.dataprovider junit4-dataprovider 2.0 test |
Hi @weiro-9-w7, I will have a look as soon as I can. How urgent is the topic for you? Cheers, |
Hi @aaschmid , |
Hi @weiro-9-w7, to be honest, I don't get your problem. Everything is working fine on my machine, see this screenshot: Test Is there another issue, I haven't understood yet? |
Hi @aaschmid , |
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 I will try to provide a fix with a new version on the weekend. Cheers, |
@aaschmid |
* the created integration tests are quite fragile currently
Hi @weiro-9-w7, Any feedback welcome. |
Hi @aaschmid , verified, thanks! |
Getting the below issue after using v2.2 |
@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())}};
}
}
}
The text was updated successfully, but these errors were encountered: