Closed JayVem closed 9 years ago
Closing this issue - I figured out a solution.
What is the solution?
I had a similar situation, when it was required to handle exactly the same method names while using DataProvider or parallel run on different configurations.
For each method I've been generaing random id (well, it could be any algorithm for generating unique ids), which was supplied within custom TestMethod wrapper along with other useful info for further reporting. Next I've just pushed this custom object into Velocity context (or whatever template engine you use for reporting) and it did the trick for further methods' recognition. However, would be nice to see something similar as a native TestNG support. I mean handling methods' duplicates.
@juherr by the way, it could be useful to add some AtomicInteger counter with appropriate getter on methods' level. It may help to recognize similar methods with different data. But anyway, it requires dynamic XmlClass modification -> adding new XmlIncludes on fly. Or we could compute total number of objects prepared by DataProvider and then modify appropriate structure before actual tests execution.
@juherr I used method level parameters in my xml and was able to access them from ITestContext in the dataprovider and listener. The parameter would be the unique id, which would be used by the dataprovider to lookup the database, fetch values and create a return object using reflection.
I now think the downside would be with overloaded methods like the previous poster mentioned, but my code base won't have them, so it works for the timebeing for me.
@sskorol I'm not sure to understand everything you propose but you're free to propose a pull-request ;)
@JayVem Ok, thank.
Still facing this issue, I need to run same method with different invocation count and thread pool size and other value every time, however I don't any way to tell the listener -- If method name -- changed or some other unique identifier, so I can't do that, I must copy this method x times with different name, any suggestions ?
Let's say, I have a class like this
When, the test runs, it would run add method twice. I want to track each invocation of add uniquely based on its input. So say, add is invoked with 1,2 as input then that's a unique invocation. If it fails, I want to store this information to a database with an \ invocation id **
How do I achieve this using testng? All of the listeners (methodinvocationlistener etc), do * not * seem to provide context that uniquely identifies a method run. Yes, they do let you see the parameters, but ITestContext itself is just a dump of the virtual XML. So, do I somehow inject my own unique parameter into the result object and track it from there?
the use case for this problem is as follows - Let's this 'Calculator' class has 10 methods. I would like the user to select which methods he wants to test from a UI, then for each method he marked for testing, he would upload data related to each method through a spreadsheet - he can upload different parameters for a single method. This spreadsheet data is persisted to the database and a key is generated. At runtime, when I generate a testng xml, it will contain these keys and the DataProvider will create input after reading the persisted data from database. Now, as you can see, I have different invocations, for tests, all of them dynamically created. I need to track them.
Sorry, this is not an issue, but something I feel is a drawback in the current testng (I would like you to correct me on this). I've raised this question on the google group and stackoverflow, but haven't received any great answers, so I am asking it here.