title: Kotlin unit test assertEquals not working
body: <p>I am trying to code a unit test in Android Studio.</p>
  
  <p>In debug mode, when I reach the breakpoint I have the following variable :</p>
  
  <pre><code>token!!.length = 392
  </code></pre>
  
  <p>And the following assertion is never ok :</p>
  
  <pre><code>assertEquals(392, token!!.length)
  </code></pre>
  
  <p>I don't understand how that can be.</p>
  
  <p>And the Run output is :</p>
  
  <pre><code>java.lang.AssertionError: 
  Expected :392
  Actual   :0
   &lt;Click to see difference&gt;
  
      at org.junit.Assert.fail(Assert.java:88)
      at org.junit.Assert.failNotEquals(Assert.java:834)
      at org.junit.Assert.assertEquals(Assert.java:118)
      at org.junit.Assert.assertEquals(Assert.java:144)
      at com.activity.screen.myapp.ExampleUnitTest.get_auth_token_isCorrect(ExampleUnitTest.kt:70)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:498)
      at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
      at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
      at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
      at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
      at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
      at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
      at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
      at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
      at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
      at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
      at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
      at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
      at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
      at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
      at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
      at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
      at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
      at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
  
  janv. 16, 2019 2:29:40 PM okhttp3.internal.platform.Platform log
  INFOS: --&gt; POST https://theauthwebsite/api/auth/token http/1.1
  
  Process finished with exit code -1
  </code></pre>
  
  <p>Source code :</p>
  
  <pre><code>    var token: String? = "" 
  
      var user = user("support@mycompany.fr","aaaabbbb", "1") 
  
      AuthService.getAuthToken(user).enqueue(object : Callback&lt;Result&gt; { 
  
          override fun onResponse(call: Call&lt;Result&gt;, response: Response&lt;Result&gt;) { 
              if (response.isSuccessful) { 
                  token = response.body()!!.result!!.token 
              } 
          } 
  
          override fun onFailure(call: Call&lt;Result&gt;, t: Throwable) { 
              token = ""; 
          } 
      }) 
  
      assertEquals(392, token!!.length)  // Here token really has a length of 392 so that it should be ok but it is not
  }
  </code></pre>
  
  <p>EDIT : The solution is to use a synchronous request so the code was modified by the following one :</p>
  
  <pre><code>token = authServices.getAuthToken(user).execute().body()!!.result!!.token
  
  assertEquals(392, token!!.length)
  </code></pre>
  
  <p>Thank you guys !</p>