Java unit testing using JUnitThe Junit tests run on the host, in an environment that doesn't include the C++ components of Chromium. This gives two problems:
You can check that the native methods are called correctly using Mockito.verify etc
C++ unit testing of classes calling JavaIf you are testing a C++ class that calls Java methods there is generally no way of stubbing or mocking the Java methods in C++ without significant code changes (e.g. creating a C++ wrapper for the Java methods). C++ unit tests can, however call Java through the JNI. For many cases calling the real Java classes in the tests works fine, however if you need to stub or mock a Java class you can do so by writing an alternative version of it, with the same native interface, and building your tests against that alternative version. One problem that can occur is that certain Android SDK methods (e.g. those of AccountManager) return their results asynchronously through callbacks. These callbacks are called through the Android event loop, so can only be called on a thread that runs an Android Looper. At least some of the unit tests (e.g. the net_unittests) run on a thread that does not call the Android looper within their message loop's Run() method. One possible solution to this is to:
base::StartTestUiThreadLooper will start such a dummy UI thread. |