realm / realm-java

Realm is a mobile database: a replacement for SQLite & ORMs
http://realm.io
Apache License 2.0
11.45k stars 1.75k forks source link

Missing unit tests when using the transformer api release #7771

Closed jd565 closed 1 year ago

jd565 commented 1 year ago

How frequently does the bug occur?

Always

Description

Just upgraded dependencies on the project. Updated to Gradle 8 and realm 10.13.2-transformer-api, AGP 7.4.1. Everything seemed to compile ok but many unit tests are not run.

Looking over the modules, if a module applied the realm plugin, it was now reporting 0 tests where it definitely had tests before. If I remove the realm plugin from being applied the tests started running again.

These tests are not using realm or mocking realm in any way but are still removed. To be clear these are unit tests (under the test folder) as opposed to instrumentation/android tests (under the androidTest folder). I tried adding testImplementation "io.realm:realm-android-library:10.13.2-transformer-api" but this made no difference.

Stacktrace & log output

No response

Can you reproduce the bug?

Always

Reproduction Steps

Project with gradle 8, realm 10.13.2-transformer-api and add some unit tests

Version

10.13.2-transformer-api, 10.12.0-transformer-api

What Atlas App Services are you using?

Local Database only

Are you using encryption?

No

Platform OS and version(s)

Mac

Build environment

No response

edualonso commented 1 year ago

We have created an umbrella ticket for all things related to Gradle 8.0. Please track progress here https://github.com/realm/realm-java/issues/7773

clementetb commented 1 year ago

@jd565 Could you confirm that this issue exists in the following scenario: 10.13.2-transformer-api AGP 7.4.1 Gradle 7.5

I wasn't able to run unit tests on that scenario, it will rule out that is related to Gradle 8.

clementetb commented 1 year ago

The issue is not related to Gradle v8 but to the new transformer implementation. No tests (unit/instrumented) can be executed if any version of Realm with the new transformer API is selected.

Instrumented tests case execution fail with:

Execution failed for task ':app:debugAndroidTestRealmAccessorsTransformer'.
(...)
Caused by: javassist.NotFoundException: io.realm.internal.RealmObjectProxy
        at javassist.ClassPool.get(ClassPool.java:422)
        at io.realm.transformer.build.FullBuild.findModelClasses(FullBuild.kt:87)
        at io.realm.transformer.build.FullBuild.filterForModelClasses(FullBuild.kt:115)
        at io.realm.transformer.build.BuildTemplate.prepareReferencedClasses(BuildTemplate.kt:86)
        at io.realm.transformer.RealmTransformer.transform$realm_transformer(RealmTransformer.kt:184)
        at io.realm.transformer.ModifyClassesTask.taskAction(RealmTransformer.kt:270)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:125)
        ... 112 more

While the unit tests does not throw any error or execute any tests.

clementetb commented 1 year ago

The issue about not resolving RealmObjectProxy on instrumented tests is because of how we handle dependencies in our gradle plugin. While we work out a solution, a workaround for running Instrumented tests is adding the realm-android-library dependency to androidTestImplementation.

We are still investigating why unit tests are not run with the transformer-api release.

clementetb commented 1 year ago

Actually, there is an issue with this workaround for it:

https://github.com/realm/realm-java/issues/7736

cmelchior commented 1 year ago

This has been fixed in 10.13.3-transformer-api