juanmendez/realm-tester


Writing tests using Realm Java

Download


Step 1. Add the JitPack repository to your build file

Add it in your root settings.gradle at the end of repositories:

	dependencyResolutionManagement {
		repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
		repositories {
			mavenCentral()
			maven { url 'https://jitpack.io' }
		}
	}

Add it in your settings.gradle.kts at the end of repositories:

	dependencyResolutionManagement {
		repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
		repositories {
			mavenCentral()
			maven { url = uri("https://jitpack.io") }
		}
	}

Add to pom.xml

	<repositories>
		<repository>
		    <id>jitpack.io</id>
		    <url>https://jitpack.io</url>
		</repository>
	</repositories>

Add it in your build.sbt at the end of resolvers:

 
    resolvers += "jitpack" at "https://jitpack.io"
        
    

Add it in your project.clj at the end of repositories:

 
    :repositories [["jitpack" "https://jitpack.io"]]
        
    

Step 2. Add the dependency

	dependencies {
		implementation 'com.github.juanmendez:Mocking-Realm:v0.11'
	}
	dependencies {
		implementation("com.github.juanmendez:Mocking-Realm:v0.11")
	}
	<dependency>
	    <groupId>com.github.juanmendez</groupId>
	    <artifactId>Mocking-Realm</artifactId>
	    <version>v0.11</version>
	</dependency>

                            
    libraryDependencies += "com.github.juanmendez" % "Mocking-Realm" % "v0.11"
        
        

                            
    :dependencies [[com.github.juanmendez/Mocking-Realm "v0.11"]]
        
        

Readme


realm-tester

-- status: tuning prior to making it work with latest Realm

This is ongoing work to unit test Realm as much as possible hammering with Mockito, and PowerMockito.

Gradle:

repositories {
...
    maven { url 'https://jitpack.io' }
}

dependencies {
...
    testImplementation 'com.github.juanmendez:realm-tester:master-SNAPSHOT'
}

Wiki has a basic instructions how to import and use this library

What has been done so far

  • Working with Realm 3.0.0
  • Supporting Robolectric 3.3.1
  • Works with Mockito 1.10.19
  • Works with PowerMockito 1.6.4
  • Have Realm.getDefaultInstance()
  • To track realm annotations, register with MockRealm your tested class annotations based on RealmAnnotations, see demo.
  • If desired, do realm configurations in a dependency class rather than an Android component see wiki.
  • Querying works for around 70% of all methods, more to come in the next phase.
  • Chaining queries
  • Asynchronous and synchronous transactions with RxJava
    • Schedulers for testing use Schedulers.immediate()
  • Support or() for chaining queries
  • Support not()
  • realmQuery.distinct(*), realmResults.distinct() has been deprecated in Realm 3.0.0
  • realmQuery.sort(), realmResults.sort()
  • Grouping
  • Querying against realmResults
  • delete reamModels in cascading mode
  • support also for deleting methods found in realmResults, realmModel, realmObject and realmLists
  • support realmQuery.*Async() methods
  • realmResults.addChangeListener(), realmObject.addChangeListener()
  • realmResults.asObservable(),realmObject.asObservable(), not supporting realm.asObservable() at this time
  • Several features not covered will simply pass, and not perform anything. In this situation, I am going to include a console message with prefix #realm-tester and let you know when that occurs. The same rule will apply for features which I cover partially