opened
ChrisA89
username_0
This depends on my pull request that fixes the rest of #68.

There are a couple of things to mention here:

 - I've moved all tests to JUnit4
 - I've inlined all mocking (so that it can happen after the Looper and Theme calls where they're needed).
 - The MockitoBase class has become BlocklyTestBase, and has methods that test need to call (where required) rather than overriding setUp (as that's not a think in Junit4).
 - There are no RunsWith annotations any more (as they weren't required).
 - All the tests still pass :)

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/google/blockly-android/465)
<!-- Reviewable:end -->
#249 Convert Tests to JUnit4
issue
created
ChrisA89
username_0
Re-based to fix git commits, and updated the commit email to be my personal one (not my work one), as I'm working on this at home, not at work.
comment
created
AnmAtAnm
username_1
I'm seeing errors on BasicFieldDropdownViewTest and BasicFieldVariableViewTest.
comment
created
ChrisA89
username_0
I'm not seeing any errors. What error are you seeing and how are you running them?
comment
created
AnmAtAnm
username_1
Abbreviate command log:

```
$ git co master
Switched to branch 'master'
Your branch is up-to-date with 'origin/master'.

$ git co -b PR465-username_0-junit4-v2
Switched to a new branch 'PR465-username_0-junit4-v2'

$ git pull https://github.com/username_0/blockly-android.git 249-junit4


$ ./gradlew cC
:blocklytest:connectedDebugAndroidTest

com.google.blockly.android.ui.fieldview.BasicFieldDropdownViewTest > testInstantiation[Nexus_7_API_19_KK(AVD) - 4.4.2] FAILED 
        java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
        at android.os.Handler.<init>(Handler.java:200)

com.google.blockly.android.ui.fieldview.BasicFieldDropdownViewTest > testUpdateFieldFromView[Nexus_7_API_19_KK(AVD) - 4.4.2] FAILED 
        java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
        at android.os.Handler.<init>(Handler.java:200)

com.google.blockly.android.ui.fieldview.BasicFieldDropdownViewTest > testUpdateViewFromField[Nexus_7_API_19_KK(AVD) - 4.4.2] FAILED 
        java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
        at android.os.Handler.<init>(Handler.java:200)

com.google.blockly.android.ui.fieldview.BasicFieldVariableViewTest > testUpdateFieldFromView[Nexus_7_API_19_KK(AVD) - 4.4.2] FAILED 
        java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
        at android.os.Handler.<init>(Handler.java:200)

com.google.blockly.android.ui.fieldview.BasicFieldVariableViewTest > testUpdateViewFromField[Nexus_7_API_19_KK(AVD) - 4.4.2] FAILED 
        java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
        at android.os.Handler.<init>(Handler.java:200)
:blocklytest:connectedDebugAndroidTest FAILED

FAILURE: Build failed with an exception.
```
comment
created
AnmAtAnm
username_1
Awesome.  Thanks again!
comment
created
ChrisA89
username_0
I still couldn't reproduce it, but i have seen that error before and I do know how to fix it.

I think the problem comes from the run order, as the solution is to run `Looper.prepare()` on the test thread, which is presumably the same thread for all tests, so if you machine runs tests in a different order to mine, it can hit tests that need that call (but don't have it) first, and on my machine, it runs a test that also needs the call, but does have it.

There's a risk that there are more tests with this problem and I'm not sure how best to uncover them. However, the solution is trivial (look at the commit I've just pushed), so if anyone comes across the problem later, we can update the tests it occurs in.
comment