osgi-test icon indicating copy to clipboard operation
osgi-test copied to clipboard

Need to obtain code coverage reports and interactive debugging within intellij and gradle plugin

Open catshow opened this issue 3 years ago • 7 comments

Is there a way to get code coverage and interactive debugging from osgi-test within intelli-j (I am using the gradle bnd plugin)?

  1. I would like to be able to run a specific test, by right clicking on it.
  2. I want to be able to see how much coverage I have from running the tests.

Thanks

catshow avatar Apr 22 '22 14:04 catshow

There is nothing specific in osgi-test for code coverage. I assume you would need to use some existing test coverage tool like jacoco or something. @kriegfrj may be know more here.

As for interactive debugging, I use Bndtools which has a "Bnd OSGi Test Launcher" Run/Debug option which you can use on the bndrun files and then run/debug your tests.

image

bjhargrave avatar Apr 22 '22 14:04 bjhargrave

Unfortunately bndtools is an eclipse only thing. I am currently running the debugger with this in my test-debug.bndrun file:

-include=./test.bndrun
-runjdb: 10001

then I have to fire up the remote JVM debugger in intellij. This is not a convenient workflow.

I think that what is needed is an implementation of a gradle TestFramework, that could be configured with a bndrun file.

I think this would also allow one to run a specific test method and not the entire test suite. Additionally, I believe it would solve the problem of having to create a whole separate integration project, because the TestFramework should receive the actual classes and methods that it needs to run.

Thanks for your consideration.

catshow avatar Apr 22 '22 16:04 catshow

I think that what is needed is an implementation of a gradle TestFramework, that could be configured with a bndrun file.

Why not use the TestOSGi gradle task type? https://github.com/bndtools/bnd/tree/master/gradle-plugins#create-a-task-of-the-testosgi-type

As TestFramework is an internal Gradle type, I don't see Bnd Gradle plugins making use of it.

bjhargrave avatar Apr 22 '22 16:04 bjhargrave

I do use the TestOSGi like this:

I have a separate debug task that use the -jdb, otherwise it will get hung up in CI builds.

val resolveTask = tasks.register<aQute.bnd.gradle.Resolve>("resolve") {
    dependsOn(tasks.compileTestJava)
    description = "Resolve test.bndrun"
    group = "test"
    bundles.from(configurations.testRuntimeClasspath)
    bndrun.set(file("test.bndrun"))
    outputBndrun.set(layout.buildDirectory.file("test.bndrun"))
}

val testOSGiTask = tasks.register<aQute.bnd.gradle.TestOSGi>("testOSGi") {
    dependsOn(resolveTask)

    description = "OSGi Test test.bndrun"
    group = "test"
    bndrun.set(resolveTask.flatMap { it.outputBndrun })
}

val debugResolveTask = tasks.register<aQute.bnd.gradle.Resolve>("debugResolve") {
    dependsOn(resolveTask)

    description = "Resolve test.bndrun"
    group = "test"
    bndrun.set(file("test-debug.bndrun"))
    outputBndrun.set(layout.buildDirectory.file("test-debug.bndrun"))
}

val debugTestOSGiTask = tasks.register<aQute.bnd.gradle.TestOSGi>("debugTestOSGi") {
    println("to find an existing java debug listening on a port use the following command")
    println("netstat -vanp tcp | grep 10001")

    dependsOn(debugResolveTask)

    // always run
    outputs.upToDateWhen { false }
    description = "OSGi Test test-debug.bndrun"
    group = "test"
    bndrun.set(debugResolveTask.flatMap { it.outputBndrun })
}

It is unfortunate that it is an internal type. :-(.

I guess I will look at maybe implementing an intellij plugin that can provide a junit platform launcher.

@bjhargrave is there a bnd gradle task that will generate a workspace, that will take a configuration. Also is there a way to specify a workspace within the bndrun file?

catshow avatar Apr 22 '22 16:04 catshow

is there a bnd gradle task that will generate a workspace, that will take a configuration.

No.

Also is there a way to specify a workspace within the bndrun file?

Normally, in a non-Bnd workspace model build like gradle, there is no Bnd Workspace and the bndrun file will be provisioned with a "standalone" workspace. What do you need from a Bnd Workspace?

bjhargrave avatar Apr 22 '22 17:04 bjhargrave

@bjhargrave

Also is there a way to specify a workspace within the bndrun file?

Normally, in a non-Bnd workspace model build like gradle, there is no Bnd Workspace and the bndrun file will be provisioned with a "standalone" workspace. What do you need from a Bnd Workspace?

I am trying to use eclipse, now. The right click run BND OSGi test launcher fails, because I don't have a workspace. I would like to generate one based on the gradle configurations, instead of manually building one.

catshow avatar Apr 22 '22 17:04 catshow

So I imported the gradle example project in this repo into an Eclipse workspace and Bnd launcher fails. Bndtools need more work to support launching bndrun files in a plain gradle project. We did work for maven support in the Bndtools m2e feature. I guess we need to do similar work for gradle to integrate with Buildship. You can open an issue in the bndtools/bnd repo to note this missing support.

bjhargrave avatar Apr 22 '22 18:04 bjhargrave

This issue has been automatically marked as stale because it has not had recent activity. Given the limited bandwidth of the team, it will be automatically closed if no further activity occurs. If you feel this is something you could contribute, please have a look at our Contributor Guide. Thank you for your contribution.

github-actions[bot] avatar Apr 23 '23 02:04 github-actions[bot]

This issue has been automatically closed due to inactivity. If you can reproduce this or if you have a good use case for this feature, please feel free to reopen the issue with steps to reproduce, a quick explanation of your use case or a high-quality pull request.

github-actions[bot] avatar May 15 '23 01:05 github-actions[bot]