Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upGitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
Use coverage without ut.run() #1025
Comments
|
Currently, utPLSQL utilizes coverage internally.
All of the above is done in single-session mode. To enable coverage gathering from outside, we would need do to some rework of internal code so that you could have one coverage for multiple sessions. Most probably, when running your tests from outside of DB, you might be utilizing more than one session.
So in essence you we would need to expose API that would allow an external program to:
We've already had similar request in the past. We would need:
I guess it could be few days - few weeks of work to get it done. |
|
So there is a way to do this on single session? So I could wrap my main jdbc connection (it uses one session) and cover at least this. That is still huge for me as I just need coverage without wrapping everything into ut.run (as I would have to wrap every call into fake test procedure because it is run from java) which is also not perfect as I will end up with as many reports as calls. |
|
Yes. In single-session mode, there is a way. The below was tested to work on v3.1.9,
The query works only once per run, as the data is consumed from buffer by query. Having all that saidI would rather have a public API for this in utPLSQL then have users hook into internal stuff. Public API could be easier to use too. |
|
I agree that having official API is a way to go so this is still a enhancement request rather than question. @jgebal Nevertheless thank you for giving me something to start with for now. |
|
I think it's a good feature to add to API. The API could be something like this:
Each test run can be executed in separate session.
The That would be pretty nice usable API I think. That change would also allow for multi-session runs therefore enabling utPLSQL itself for parallel test execution! There are two options though to consider:
I would prefer the first option as it also takes care of cleaning-up profiler and coverage tables. This is something utPLSQL is not handling at the moment. I must say - this feature work looks pretty exciting :) |
|
I agree on that approach as there is almost no reason why we should keep the data after report is generated. One possible scenario is when you want to generate multiple types of report from single run. |
|
@pesse @PhilippSalvisberg @lwasylow I see it's definitely doable from implementation side and probably not a huge change. |
|
I like the approach. The CLI should be extended to produce reports (e.g. using The start/stop mechanism is flexible enough. It can be used explicitly during test runs or included in a logon/logoff trigger to further simplify the usage. That way everything executed under a defined user is covered and the profiling data is cleared after the completion of the report. |
|
I like the feature, too. Will have to think about what that means for CLI and java-api. It sounds like it'll lead to more modularization, which is a great thing. |
|
Is there any ETA for that as I am moving closer and closer to the point when I would love to introduce code coverage. I could of course use junky hack discussed above but if there is any chance for pre-release, bleeding edge alpha implementation then I'm all in ;) |
|
HI @ksawerykarwacki |
|
@ksawerykarwacki - will need another weekend or two to get into this. This long Easter weekend I have decided to actually get some rest. |
|
Is there some progress by any chance? |
|
Sorry @ksawerykarwacki |
|
No problem. I hope everything is fine for you now. I finally tried the old janky workaround and it didn't work for me as reporting returns 0 lines covered even thou I run a procedure form my schema. But I tested that on latest version so it might no longer work. Anyway I still can't wait to lay my hands on full api :) |
|
@ksawerykarwacki - did you get a chance to try the new coverage approach in #1079? |
|
I'm on vacation for past couple of weeks and I try to avoid coding :) I'll be back to my regular office routine in a week after that I'm going to prepare some tests and run it. To give you some way how I will test it: I tried to run the workaround approach from #1025 (comment) using java as described above but generated report was always empty. Due to lack of time to investigate this I just dropped it and was waiting for full implementation. I'll get back to you as soon as I will get some results after my holiday break. |
|
I've run some initial test and seems to work like a charm. I had few doubts about configuration of reporter as documentation lists all parameters except coverage_run_id as optional so my assumption was that something like this:
should generate me report for all schemas where ut_runner.coverage_start/ut_runner.coverage_stop occurred. That didn't happened and I had to add schema to parameters which makes it not so optional ;) Generally I'm pretty pumped about it, start/stop takes almost no time so overhead is minimal, the fact that we can generate multiple reports for different purposes is awesome. One thing for consideration is to add option to remove data for specific run_id. Without auto cleanup after generation of report for multiple runs it may be just a lot of unused data clogging datafiles. Something like ut_runner.coverage_clean(a_coverage_run_id) might be useful especially if code coverage is generated over multiple run_ids and over many big schemas. Overall 10/10, would recommend this to my family and friends ;) |
|
@jgebal I also struggle with some file mappings as my structure is a bit different. My folder structure looks like this:
I don't know how to do mapping if I have additional folder level for packages |
|
@ksawerykarwacki
Coverage is gathered on all schemas (regardless of connected user. When reporting, you need to specify which schemas or objects you're interested in for coverage reports. |
|
For the mapping, you will need a clever regex, depends on your file names too. Can you provide a more detailed example of what would be file names and extensions for given objects? All of this decides on config for report. If you will provide more details I can give you some help with that. |
Describe the bug
I'm super happy with coverage provided by utPLSQL however my company uses testing framework written in java with additional code run with sqlplus for integration tests. Is there any way to manually start, stop and generate sonar report without wrapping every piece of code with utplsql?
It would be great as my PL/SQL code is fragmented and called from different places but I would love to be able to get the coverage. I found that this project uses dbms_profiler so it shouldn't be a problem. Is there any instruction how to do this?
Provide version info
utPLSQL 3.1.9
Oracle 12.2
Information about client software
Other, using jdbc