Various technical articles, IT-related tutorials, software information, and development journals
Wednesday, January 30, 2019
Robolectric doesn't like spaces in the user profile path
Today I helped someone who was trying to run Robolectric tests but found that they crashed with a FileNotFoundException for a JAR somewhere under their user profile directory. This user's profile folder had a space in the name that the error message displayed as %20. Apparently the path was getting URL-encoded somewhere along the way. We worked around the problem by creating a symbolic link (mklink /d) in C:\Users from the mangled name to the actual user profile folder.
Tuesday, January 29, 2019
When JUnit tasks get stuck in "No tests were found"
Tonight I needed to troubleshoot some Android Studio JUnit run configurations failing with "no tests were found." Interestingly, they would work fine until the user tried to run them in the presence of a compile error, at which point they would stop working until a Build | Rebuild Project, even if the compile error was fixed. It was fixed by adding a before-launch task to the run configuration that runs the clean Gradle task for the module. Later it was found that a plugin was interfering with the build process.
Sunday, January 27, 2019
Exotherm - Connection maintenance is working
When I hibernated my computer last night, I had Exotherm running and connected. When I started back up this morning, I found that it quickly reconnected to the server without my intervention. It was also able last night to remain online for a long time without getting confused about its connection state. So it looks like the connection keep-alive code is working.
Saturday, January 26, 2019
Exotherm - Maintaining connection
I previously found that Exotherm tended to lose its connection to the FICS after a while of idling. That wasn't even due to the automatic one-hour idle log-out; the bot and the FICS just disagreed about whether it was online. Today I rearranged its FICS interface some more so that it will try to reconnect if it finds that the connection was lost. Also, after 5 minutes of no input or output, it will send a chat to itself through the server just to keep the connection alive. These changes should make it suitable for deployment as a long-running process on my server.
Volley and Robolectric
Yesterday I set up unit testing for an Android project using the Robolectric test framework. The app depends on Volley, which works fine in Android. But trying to run the unit test in the JVM produced a crash stating that the org.apache.http.client.HttpClient class could not be found. I tried adding empty classes with the appropriate names to sidestep that error and similar subsequent ones, but couldn't get the test to start. Eventually I found that Robolectric provides a shadow implementation of the necessary classes, but it's in another dependency. Adding that to the Gradle project file fixed the problem:
testImplementation 'org.robolectric:shadows-httpclient:4.1'
testImplementation 'org.robolectric:shadows-httpclient:4.1'
Thursday, January 24, 2019
When ClassCastException is thrown from Mockito-mocked functions
Today I needed to mock some methods on a Java static class for unit testing. I used PowerMockito because, as far as I can tell, Mockito cannot mock static classes, but the two tools have very similar functionality. I used when, then , and thenCallRealMethod to run other code and then return the normal result, but found that a ClassCastException was thrown in the mocked method. The stack trace didn't provide a line number for that frame, and the argument types were correct in the calling code, so I was confused.
I had accidentally used lambda syntax to return something from the then handler that was not of the method's return type. When PowerMockito tried to use that as the return value, the exception was generated. Apparently chaining thenCallRealMethod after then is ignored.
I had accidentally used lambda syntax to return something from the then handler that was not of the method's return type. When PowerMockito tried to use that as the return value, the exception was generated. Apparently chaining thenCallRealMethod after then is ignored.
Monday, January 21, 2019
Some build.gradle features aren't available for Android modules
Today I tried to merge a Java project into an Android module so that a Gradle plugin could act on the entire codebase at once. I found that many features are provided by the Java plugin for Gradle (apply plugin: 'java') but not the Android plugin (apply plugin: 'com.android.application'). Unfortunately, those two plugins cannot be applied at the same time. It looks like I'll need to rewrite the custom plugin to work with the Android project.
Subscribe to:
Posts (Atom)