editing `Day 47` - Fixed both Emulator issues - Fi...
# 100daysofkotlin-2021
b
editing
Day 47
• Fixed both Emulator issues • Fixed Testing Issue
Self-Comment
• Ha! Conquered them both. It may have taken me all day(on top of the last couple of days.. lol), but at least it's done and I can go back to being productive. The problems and fixes are posted in the thread. I actually enjoyed writing my daily report this way, it helped document progress and kept me consistent throughout the day as I've been getting distracted more and more lately. Might try this again. • Hopefully I won't come across too many issues going forward, but I'm excited to enter the world of testing for a bit. It feels completely different than what I've been doing and I believe it will help me understand some of the other issues I've come across more in depth. I'm not sure where I'll begin my tests(probably keep up with database tests, I suppose I'll go to github and start viewing sample tests from others). I will have to learn how small I should go to write tests. Will take some time to learn this. I wonder if I should learn in another sample app from scratch before going back to implement in Daily Doc? Since there is so much going on. Hmm.. 🤔🤷‍♂️
Goals Tomorrow
• Continue Testing venture 😊
Emulator now works after searching through the issuetracker to find an older version. Reinstalled Emulator package in my sdk folder. Now an issue with building current project:
fixed by adding dependencies. Issue above still occuring
Solved! After uninstalling Android Studio (for the 5th time) and deleting the file mentioned here , it seemed to have solved itself. I tried quite a few other methods mentioned throughout StackOverflow and elsewhere, but nothing worked besides deleting the file
Copy code
C:\Users\YourUserName\AppData\Roaming\Google\AndroidStudioPreview4
This fixed my issue with running tests. For some reason is was finding duplicate META files. Added
packagingOptions
mentioned here
Copy code
packagingOptions {
        exclude("META-INF/*.")
    }
My current issue with Testing. The example test given works, and basic unit tests were fine as well. It seems I'm struggling with the Instrumentation test when trying to test my database. Why is it failing to instantiate? 🤔
Copy code
java.lang.RuntimeException: Failed to instantiate test runner class androidx.test.internal.runner.junit4.AndroidJUnit4ClassRunner


	at androidx.test.ext.junit.runners.AndroidJUnit4.throwInitializationError(AndroidJUnit4.java:121)
	at androidx.test.ext.junit.runners.AndroidJUnit4.loadRunner(AndroidJUnit4.java:113)
	at androidx.test.ext.junit.runners.AndroidJUnit4.loadRunner(AndroidJUnit4.java:74)
	at androidx.test.ext.junit.runners.AndroidJUnit4.<init>(AndroidJUnit4.java:48)
	at java.lang.reflect.Constructor.newInstance0(Native Method)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
	at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:104)
	at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:86)
	at androidx.test.internal.runner.junit4.AndroidAnnotatedBuilder.runnerForClass(AndroidAnnotatedBuilder.java:63)
	at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:70)
	at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:37)
	at androidx.test.internal.runner.AndroidRunnerBuilder.runnerForClass(AndroidRunnerBuilder.java:153)
	at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:70)
	at androidx.test.internal.runner.TestLoader.doCreateRunner(TestLoader.java:73)
	at androidx.test.internal.runner.TestLoader.getRunnersFor(TestLoader.java:105)
	at androidx.test.internal.runner.TestRequestBuilder.build(TestRequestBuilder.java:804)
	at androidx.test.runner.AndroidJUnitRunner.buildRequest(AndroidJUnitRunner.java:575)
	at androidx.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:393)
	at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:2205)
Caused by: java.lang.reflect.InvocationTargetException
	at java.lang.reflect.Constructor.newInstance0(Native Method)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
	at androidx.test.ext.junit.runners.AndroidJUnit4.loadRunner(AndroidJUnit4.java:104)
	... 17 more
Caused by: org.junit.runners.model.InvalidTestClassError: Invalid test class 'com.lid.dailydoc.data.local.NoteDatabaseTest':
  1. Method setUp() should be public
	at org.junit.runners.ParentRunner.validate(ParentRunner.java:525)
	at org.junit.runners.ParentRunner.<init>(ParentRunner.java:92)
	at org.junit.runners.BlockJUnit4ClassRunner.<init>(BlockJUnit4ClassRunner.java:74)
	at androidx.test.internal.runner.junit4.AndroidJUnit4ClassRunner.<init>(AndroidJUnit4ClassRunner.java:43)
	at androidx.test.internal.runner.junit4.AndroidJUnit4ClassRunner.<init>(AndroidJUnit4ClassRunner.java:48)
	... 20 more
Interesting, every Room Database test tutorial I came across has
@Before
used instead of
init
. Before is supposed to create the database before each test and After closes. I couldn't find any information to help me with this and started to change some things on my own. Finally decided to change the db creation to init instead and it worked! I will hold off on optimizing and leave it for now unless more issues arise. It's been an eventful few days dealing with technical issues. But all solved!
371 Views