reportportal / agent-java-testNG

TestNG listener
Apache License 2.0
54 stars 20 forks source link

Logs from TestNG DataProvider methods are captured and associated with the corresponding test in ReportPortal. #202

Open akshayamaldhure opened 1 year ago

akshayamaldhure commented 1 year ago

I understand that the logs from the various hooks (like all the methods annotated with @Before* and @After*) and all the @Tests are available for viewing in Reportportal. However, I did not see those coming from the methods annotated with @DataProvider. This makes it a bit challenging to debug any issues related to construction/population of the test data. Please let me know if I'm missing anything here.

DzmitryHumianiuk commented 11 months ago

@HardNorth looks like another good thing to consider. I'm not sure if we report this level of logs anyhow right now.

HardNorth commented 11 months ago

@DzmitryHumianiuk I doubt this is really possible. Data providers are called before test creation. So the only option is launch logs, where, I believe, it is already reported.

DzmitryHumianiuk commented 11 months ago

@akshayamaldhure look if you can see them in Launch's Log view: blue icon in a line with List view -> Unique Errors -> Log VIew

image
akshayamaldhure commented 11 months ago

@DzmitryHumianiuk Apologies for the delayed response. I do not see the logs from my @DataProvider annotated method under Log View either. The logs logged using the same logger from other methods (like the ones annotated with @Test are visible in Reportportal).

Screenshot 2023-11-01 at 2 42 08 PM

DzmitryHumianiuk commented 11 months ago

@akshayamaldhure, in that case, it looks like we need to implement this on the agent side of the ReportPortal integration to properly capture these log types. As @HardNorth mentioned, since the data provider initializes before the actual test case, we don't have an active test case ID to tie the logs to.

We'll need to develop a mechanism that allows us to link logs to a test case that hasn’t been created yet. This could potentially be managed with a promise object that anticipates the expected ID, or by pre-determining the test case ID before its initialization.

So, to give you a straightforward answer: this functionality isn't currently available.

DzmitryHumianiuk commented 11 months ago

@akshayamaldhure, with your permission, I'll keep this request open and reclassify it as a feature request. I'd like to hold onto it in our backlog so that sooner or later, we consider implementing it as part of our standard functionality.

HardNorth commented 1 week ago

@DzmitryHumianiuk What you saying is not even possible. We just simply don't have any reference on Test Case. No any "promises" would help you, because you won't chain them with currently running test, unless it's single-threaded execution.

DzmitryHumianiuk commented 1 week ago

@HardNorth, as far as I remember from the inner workings of TestNG, the relationship between the DataProvider and the method using it is formed in a single thread. So, there shouldn't be a situation where the DataProvider runs in a separate thread. It seems that TestNG structures the call sequence starting with the method, and if the method has a DataProvider, it adds it to the call sequence before the method. This applies to the number of threads involved.

What I mean by "promise" is essentially deferring the submission of logs related to the DataProvider until the next active test appears. When the next active test starts, we would assign its ID to the logs from the DataProvider, which are temporarily stored in a thread-safe collection.

Right now, the logs are likely generated and sent without belonging to a specific testItem and are assigned at the launch level. But if we delay them, knowing they’re from the DataProvider, and assign them to the next upcoming TestCase ID, this could be a solution.

These are my theoretical ideas — reality might differ.