Uploaded image for project: 'Realm Java SDK'
  1. Realm Java SDK
  2. RJAVA-96

Realm Transformer not correctly applied to classes inside androidTest

    • Type: Icon: Bug Bug
    • Resolution: Cannot Reproduce
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None

      Bug Details

      I've just recently started trying to add instrumented tests to my application project so that I can test the portions of my code which have to do with data manipulation and persistence (which is much of the code).

      I tried to start out small by adding a test class, RBookTest which tests just one method I have on one of my model classes, RBook. However, when I run the :app:assembleDebugAndroidTest task to assemble the test APK, Realm's bytecode transformer is causing the build to fail when it gets to this line in RBookTest:

      book1.isNew = false;
      

      I've attached a log with more content in the Actual Results section, but this is the top-level failure message from Gradle:

      Execution failed for task ':app:transformClassesWithRealmTransformerForDebugAndroidTest'.
      > javassist.CannotCompileException: [source error] realmSet$isNew(boolean) not found in com.bkromhout.minerva.realm.RBook
      

      I should note that I'm having absolutely no issues assembling the regular debug APK (the :app:assembleDebug task), and am aware of a few places which use the same sort of line as the problematic one in the test class.

      Expected Results

      I should be able to compile the test APK (using the :app:assembleDebugAndroidTest) in order to run instrumented tests on an Android emulator or device.

      Actual Results

      Running the :app:assembleDebugAndroidTest task fails. I've attached a file which contains the log output which results from running that task with the -info and -stacktrace options, but have omitted the output of all but the :app:transformClassesWithRealmTransformerForDebugAndroidTest task for brevity: Log.txt

      Steps & Code to Reproduce

      I think the steps to reproduce the issue are fairly self-explanatory. The app's code is open source, so if you want to clone it to try and reproduce the issue, use this link to the repo (commit hash 3366874f7b). That's the commit where I pushed the affected test class, RBookTest. The transformer seems to be choking when it tries to manipulate the setter on line 48 (book1.isNew = false).

      If you just want to quickly reference the relevant files, here are links to a couple of them as of that commit:

      A few other possibly-relevant points of note:

      • I'm using retro-lambda
      • I have a copy of TestRealmConfigurationFactory from your own suite of tests (very cool idea btw!), and am using it as a Rule for RBookTest so that it doesn't interfere with the usual Realm file

      IMPORTANT EDIT I've just realized that I was also in the process of testing a custom fork of another library called epublib around this time.
      While that has no bearing whatsoever on the issue at hand, it will cause you issues if you try to import the project directly as it is at the time of that commit. In order for you to be able to import the project cleanly, you'll need to edit the settings.gradle file in the root of the project so that it only contains the following content:

      include ':app'
      

      Sorry for the confusion!

      Version of Realm and tooling

      Realm version(s): 1.0.0

      Android Studio version: 2.1.1

      Which Android version and device: x86 Emulator running API 23 with Google APIs

            Assignee:
            Unassigned Unassigned
            Reporter:
            unitosyncbot Unito Sync Bot
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: