1

I've got maven project in Android Studio. I'm using Robolectric with Roboguice to simplify testing of the app.

I have about 30 tests written. All of them work fine in the IDE, but 2 of them fail when I run them with

mvn test

The tests fail on Fragment which is added to Activity by XML. The onActivityCreated method of this fragment, accesses an injected reference which is apparently null at this point (causing NPE).

I'm wondering what can be the difference in the runtime environment between AS and pure maven.

EDIT:

The object marked as singleton was released in the previous test, causing the NPE. Somehow AS test runner works differently from maven, running the test in different context. Any idea how is it possible?

kmalmur
  • 2,809
  • 3
  • 29
  • 37
  • Could be AndroidManifest location is different – Eugen Martynov Jul 11 '14 at 09:59
  • 2
    Maybe related to how Maven handles parallel test execution. See related discussion http://stackoverflow.com/questions/3365628/junit-tests-pass-in-eclipse-but-fail-in-maven-surefire and official documentation [Fork options and parallel execution](http://maven.apache.org/surefire/maven-surefire-plugin/examples/fork-options-and-parallel-execution.html) – iluu Jul 11 '14 at 15:45

1 Answers1

0

Karolina was right, the difference is in configuration of AS test runner and Maven Sunfire (more specifically in the number of threads that execute the tests). Thanks

kmalmur
  • 2,809
  • 3
  • 29
  • 37