Skip to content

Implement the new test-runner's API usage#35

Merged
martinezmatias merged 9 commits intoASSERT-KTH:masterfrom
andre15silva:covered-test-result-api
Jun 29, 2021
Merged

Implement the new test-runner's API usage#35
martinezmatias merged 9 commits intoASSERT-KTH:masterfrom
andre15silva:covered-test-result-api

Conversation

@andre15silva
Copy link
Copy Markdown
Member

@andre15silva andre15silva commented Jun 24, 2021

This PR implements the usage of the new test-runner's API.

On important aspect is that the CoverageCollectorDetailed transformer doesn't consider constructor coverage (See https://github.com/STAMP-project/test-runner/blob/5b84d1a940564a1c1ee0b22b695503fab4600d97/src/main/java/eu/stamp_project/testrunner/listener/impl/CoverageCollectorDetailed.java#L45-L52), so I have modified the existing tests to follow that.

Also, test-runner doesn't support test coverage by default, so to support that we need to implement it in EntryPoint as an option too.

I'm not entirely sure this is what we want to do tho, as some constructors may have bugs and the coverage there will be important. WDYT?

@andre15silva
Copy link
Copy Markdown
Member Author

Another important issue is that the test suite is failing (at least locally) when the tests are run all together due to:

Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: org/junit/platform/launcher/TestExecutionListener
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:756)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:468)
at java.net.URLClassLoader.access$100(URLClassLoader.java:74)
at java.net.URLClassLoader$1.run(URLClassLoader.java:369)
at java.net.URLClassLoader$1.run(URLClassLoader.java:363)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:362)
at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352)
at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
at java.lang.Class.getMethod0(Class.java:3018)
at java.lang.Class.getMethod(Class.java:1784)
at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:650)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:632)
Caused by: java.lang.ClassNotFoundException: org.junit.platform.launcher.TestExecutionListener
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352)
at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
... 19 more

It's really weird, specially because test-runner itself runs several tests too in its test suite and doesn't have this issue (I've also checked the pre-conditions and there don't seem to be any that affect this).

Have you ever come across an issue like this? (maybe @danglotb?)

@martinezmatias
Copy link
Copy Markdown
Collaborator

Hi @andre15silva

On important aspect is that the CoverageCollectorDetailed transformer doesn't consider constructor coverage

Does it mean it should the necessary to remove this if condition on test-runner?

@andre15silva
Copy link
Copy Markdown
Member Author

Does it mean it should the necessary to remove this if condition on test-runner?

In this case, we would add a new option to EntryPoint, but yes, if we want coverage for the constructor instructions we need to do it. WDYT?

@martinezmatias
Copy link
Copy Markdown
Collaborator

we would add a new option to EntryPoint

An option would be fine, which by default does not compute coverage of constructor. Otherwise the change will break the test-runner.

@andre15silva
Copy link
Copy Markdown
Member Author

An option would be fine, which by default does not compute coverage of constructor. Otherwise the change will break the test-runner.

Alright. I suggest we do it separately from STAMP-project/test-runner#95, so it doesn't get bigger than it already is.

@martinezmatias
Copy link
Copy Markdown
Collaborator

I suggest we do it separately from STAMP-project/test-runner#95, so it doesn't get bigger than it already is.

Fine.

@danglotb
Copy link
Copy Markdown
Contributor

Hello,

I remember to have already the mentioned issue:

Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: org/junit/platform/launcher/TestExecutionListener

AFAIR, the classpath was missing a dependency like junit-platform-launcher:

<dependency>
            <groupId>org.junit.platform</groupId>
            <artifactId>junit-platform-launcher</artifactId>
            <version>1.3.2</version>
 </dependency>

This happens when you run the test suite of flacoco locally, isn't it? When I manage to have some time, I'll try to have a look at it.

@andre15silva
Copy link
Copy Markdown
Member Author

andre15silva commented Jun 24, 2021

Hello,

Hi @danglotb

This happens when you run the test suite of flacoco locally, isn't it? When I manage to have some time, I'll try to have a look at it.

It happens when I run the whole test suite, and sometimes when I run test methods individually.

For example:

# set up test projects
./.github/install_examples.sh

# this works
mvn -Dtest="CoverageRunnerTest#testExampleFL1" clean test

# this results in several failures, including the test that passed above
mvn clean test

In CI the behavior seems to be the same.

Also, I tried adding that dependency but didn't do anything.

@danglotb
Copy link
Copy Markdown
Contributor

Hi @andre15silva,

It seems that here you gather the required jars from the folder ./examples/libs/.

However, one of them, i.e. junit-jupiter-api-5.7.2.jar, is missing (./examples/libs/).
Thus, it seems that test-runner needs (for now) the following jar:

org/junit/platform/junit-platform-launcher/X.Y.Z/junit-platform-launcher-X.Y.Z.jar

On my side, X.Y.Z = 1.3.2. Adding this jar might require adding some others jars to make JUnit5 works.

The actions that could be taken are:

  • Add the required jars to the ./examples/libs/ folder.
  • Or refactor test-runner in order to not need the junit-platform-launcher

Hope it can help! :)

@andre15silva
Copy link
Copy Markdown
Member Author

Hi @danglotb ,

Thank you for your time.

You are right, when I added the remaining jar files to the classpath some of the tests started working.

I implemented a way of having default classpaths and configurable ones. I think for now it works, but integrating it in test-runner probably wouldn't be a bad idea either.

In other news, I spend way too much time debugging test-runner and flacoco just to find, in the end, that because EntryPoint options weren't getting reset (I thought they were) and that ended up running the JUnit5 runner for JUnit4 examples.

Anyway, that should now be fixed and this PR is now ready for review (@martinezmatias ?)

@andre15silva andre15silva changed the title WIP: Implement the new test-runner's API usage Implement the new test-runner's API usage Jun 29, 2021
Signed-off-by: André Silva <andre15andre@hotmail.com>
Constructors are no longer considered in the computation of coverage, so
we remove them from tests.

Cover tests option is not yet supported through test-runner's
EntryPoint, so we make it unsupported temporarily.

Signed-off-by: André Silva <andre15andre@hotmail.com>
Signed-off-by: André Silva <andre15andre@hotmail.com>
Signed-off-by: André Silva <andre15andre@hotmail.com>
Signed-off-by: André Silva <andre15andre@hotmail.com>
I literally spent 5 or 6 hours debugging this and test-runner, just to
in the end realize it was simply running the wrong test framework.

Signed-off-by: André Silva <andre15andre@hotmail.com>
Signed-off-by: André Silva <andre15andre@hotmail.com>
Signed-off-by: André Silva <andre15andre@hotmail.com>
@andre15silva andre15silva force-pushed the covered-test-result-api branch from 1f82b17 to 06e6aa6 Compare June 29, 2021 12:20
@andre15silva
Copy link
Copy Markdown
Member Author

Rebased and ready for review.

public class FlacocoMain implements Callable<Integer> {
static boolean log = true;

@Option(names = { "-w", "--workspace"}, description = "Path to the workspace directory of flacoco.", defaultValue = "./")
Copy link
Copy Markdown
Collaborator

@martinezmatias martinezmatias Jun 29, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder how it would work when we use Flacoco with a Jar: it will not be a workspace

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I understood. I just ran the jar with that option and it works fine.

That option, for now, is only passed to test-runner, which will then save and load serialized files inside of it.

How could running it through the packaged jar result in different behavior?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, perfect. I misunderstood. Sorry :)

Signed-off-by: André Silva <andre15andre@hotmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants