-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Test data as code feature concept #2724
Comments
Sounds like a |
I don't catch the difference between It sounds to me like a SPI on top of the data provider logic. Am I right? |
@cbeust , @juherr Data provider's code will never be unloaded from heap, so it's not really scalable to put a data generation code there, because it will sit in RAM for entire test run and may eventually lead to OOM, As for junit implementation, I don't know if they unload their method providers, after use. Will look at it later. Maybe we may make dynamically load / unload dataproviders, when it's possible, i.e. when dataprovider is in different class? |
Ok. I'm just a bit surprised because our known memory problem is on the test results. If we are going to the way you say, is there any reason to not implement the current data provider feature over it? If you plan to try something, please share your results here. |
Yes, if we do dataproviders unloadable, test data may be written as a data provider in a separate class, loaded on demand, and unloaded after data is generated. I never met teems, coding any sophisticated data in dataproviders. I think there was some reasons for that:
But when memory consumption will not threat scalability, and with scripting language usage it makes sense for me. |
@dsankouski - I am still not sure as to what problem are we trying to solve here. Can you please help me understand that ? I ask this because, TestNG always remembers the parameters that were passed to a So can you please break down the problem statement into a bit more elaborate details so that I can understand the problem statement. May be a Java example could be more explanatory (if possible that is) |
Suppose, you're decided to use data provider, like in example: import org.testng.annotations.DataProvider;
class DataProviders {
@DataProvider
public static Object[][] dp() {
return new Object[][] {
{"Mike", 34, "student"},
{"Mike", 23, "driver"},
{"Paul", 20, "director"}
};
}
}
class Test {
@Test(dataprovider = "dp", dataproviderClass = DataProviders.class)
public void test(String name, int age, String prof) {
// test code
}
} All data in When dp method is invoked, With current DP implementation we end up with data being duplicated Since we only need data itself, i.e. Few words about interned strings: Note, $2.5.4 states: |
@dsankouski - Wow that's an amazing insight into the internals of the JVM. Thank you for taking the time to share that. I will go through it in detail and come back. In the meantime if I understand your requirement, you are basically proposing a way wherein I can basically have the following for a data driven test
Is my understanding correct ? If it's correct, then this is a very specialised usecase for data providers, because usually people build data providers that feed off an external data source (xml|xls|json|yaml|db|csv) and so there's no need for loading/unloading one class because it wouldn't have any fields that are constants as in your example. PS: My knowledge on the JVM internals is very primitive, so please bear with me if my questions sound naive.. Excited to understand this even more from a personal learning perspective :) |
1 - correct So, what I'm thinking of, is to add This indeed may be specialized case. Because, when we're got |
Yes. It has to be a string parameter so that we can use reflection backed by a custom class loader to be used to load up the class. Then again, I think you would also need to consider providing a means to inject a custom class loader itself. So would it basically mean that we would now need to add up 2 string parameters (1 which specifies the data provider class and the other which specifies the custom class loader that we would like to be used.). I say this because if we end up specifying the classloader as a class parameter then we are back to square one. |
TestNG Version
The point of this concept is to write test data files as code on kotlin
(or any other language). This allows to put dynamic data
(i.e. generated on each launch, for example, today's date or random string)
into data files.
The problem:
I was involved in a project, where test data was stored in yaml files.
They parsed those yaml files, and used it in a tests.
The problem was, they needed dynamic values,
like today's date, or random sequence of characters.
This data cannot be places in yaml testdata files by default.
So they used custom markup language, to define, for example random alphabetic sequence
of length 6. This custom markup language was processed by custom yaml deserializer,
to replace markup with calculated values. In this case, why can't we write test data
in code?
How test data as kotlin code may look like?
Kotlin code may seem like declarative language, when using named constuctors
for example:
The problem with this approach is that all data-generation code, and consequently
data(because it's essentially hardcoded) remains in RAM, and may lead to OOM.
We may overcome this with custom classloader, for example:
How a test class may look like?
What do you guys think? Would you accept such feature in testNG?
The text was updated successfully, but these errors were encountered: