Category Archives: Uncategorized

Testing Mozilla Stumbler

Programming on Android is 97 kinds of awful.

The default choice is to use JUnit, which is mostly useless if you are using anything in the android.* namespace as a regular JVM will grind to a halt and die.

If you use robotium, you’re now involving at least an Android VM, or possibly running on real hardware – but the costs is that you will need to either spin up that VM or you need to have a device plugged in. Running tests involves loading code into your Android machine, starting up a full application and then instrumentation. This is slow and painful.

For Mozilla Stumbler, we made the choice to use robolectric[1] Robolectric fixes the “time to run tests” problem really well. Tests run in a regular JVM, they run reasonably quickly and you can get things running in a continuous integration platform without too much pain. We use it on Travis for the stumbler. Robolectric will play nice with JUnit4 so it’s not entirely jarring trying to wrap your head around it.

Your best bet here is to start reading some code to see what to do – a good place to start is the code that tests our software update in github.

@Config(emulateSdk = 18)
public class UpdaterTest {

    private Context ctx;
    private MainDrawerActivity activity;

    public void setUp() throws Exception {
        ctx = Robolectric.application;
        activity = Robolectric.newInstanceOf(MainDrawerActivity.class);
        Updater.sLastUpdateCheck = 0;

    public void testUpdater() {
        IHttpUtil mockHttp = new MockHttpUtil();

        Updater upd = new Updater();
        upd = spy(upd);

        // Setup mocks.
        // Replace the HTTP client and clock
        MockSystemClock clock = new MockSystemClock();
        long now = System.currentTimeMillis();
        ServiceLocator.getInstance().putService(IHttpUtil.class, mockHttp);
        ServiceLocator.getInstance().putService(ISystemClock.class, clock);

        // skip the exclusive wifi-only check

        assertFalse(upd.checkForUpdates(activity, ""));
        assertFalse(upd.checkForUpdates(activity, null));

        assertTrue(upd.checkForUpdates(activity, "anything_else"));
        assertEquals("1.3.0", upd.stripBuildHostName("1.3.0.Victors-MBPr"));
        assertEquals("1.3.0", upd.stripBuildHostName("1.3.0"));

Things to note:

You’re going to need the two annotations @Config and @RunWith on the test class to ensure that robolectric is enabled when your test is executed. If you forget these – you’re going to get bizarre errors when the regular JUnit4 tries to execute your testcases.

If you haven’t used JUnit in a long time, you’re also going to have to get used to the @Before and @Test annotations. Apparently things have changed in 10 years and methods named setUp or starting with test are no longer automatically picked up by JUnit.

There’s quite a bit happening in this little test. The Updater class is instantiated and we immediately wrap that with
a mockito spy. This lets us dynamically stub out behaviour – usually to no-op some function. In this case, we want to trick the Updater into thinking that a network is always available.

We also use a service locator pattern to dynamically inject dependencies into the stumbler. In this test, we inject
a fake system clock so that we can instrument time. The Updater class checks the system clock periodically – we want to
ensure that our test case runs the Updater with a known time.

The rest of the test case is the usual JUnit assertions.

If you run the tests from command line using : make test, you’ll get nice HTML output showing you your test results under the android/build/test-report/github/unittest/index.html path.

Library tests are also executed by make test and will show up under libraries/stumbler/build/test-report/debug/index.html

Those are the basics – robolectric lets you instrument android UI bits as well which I’ll cover in the next post.


Campbell Walsh Urology 11th Edition will revise PVPS risks to 1-2% of patients

I win at the internet.  Sort’ve.

Post-vasectomy pain syndrome has had this “1 in 1000” patient number floating around for a while, and I’ve never been able to track down where it came from until the last couple of months.   Turns out – that numbers is bunk.

After a series of 35 emails back and forth with Elsevier, the publisher of Campbell Walsh Urology – I can confirm now that the 11th edition will include dramatically higher risks for incurring post-vasectomy pain syndrome.

The 10th edition has this to say on the topic:

Up to 30% of men have short-term scrotal pain lasting a few weeks. However, postvasectomy pain syndrome, or long- term scrotal pain after vasectomy, occurs in approximately one in 1000 vasectomies, although some report the incidence to be as high as 15% (McConaghy et al, 1996; Awsare et al, 2005; Tandon and Sabanegh, 2008).

If you take the time to go through those citations, no such claim is actually made.

McConaghy 1996:

Following a study by McMahon et al. which found that 33% of patients were troubled with chronic testicular discomfort following vasectomy [1], a study was undertaken at our hospital to examine ways of reducing the incidence of this problem. This work has been published recently [2] and we would like to draw your readers’ attention to the relevant findings.

This may result from congestive epididymitis or the development of sperm granuloma. The incidence of chronic orchalgia is quite high (12–52%). [5] The proportion of patients, however, whose quality of life was affected, or those who sought treatment was much lower (2.2–15%)

Tandon 2008 is more complex.  It has this to say:
PVPS is disappointingly common and difficult to treat. Although early pain lasting for a few weeks is fairly common after vasectomy (present in up to 30% of men), longterm pain requiring some kind of intervention or surgical therapy occurs in up to one in 1000 vasectomized men [4].
Tracking down the claim for one in 1000 vasectomized men in citation 4 gives us :
Sandlow JI, Winfield HN, Goldstein M. Surgery of the scrotum and seminal vesicles. In Wein AJ, Kavoussi LR, Novick AC, Partin AW eds, Campbell-Walsh Urology, 9th edn. Philadelphia: WB Saunders, 2006: 1103–9

So what we have is Campbell Walsh citing a paper which cites Campbell Walsh.

There’s never been any evidence that supported the claim of 1 in 1000 number.

So that’s the good news.  That number is going away.

I’m told by the reviewers in Elsevier that they will be using Leslie 2007 for most of their new data and they will also be using the AUA guidelines.

Unfortunately, you won’t be able to verify this until 2016 because Elsevier can’t seem to figure out how to use the internet to publish errata.

Yes – you will need to wait for the dead tree version of the book to come out.

The irony here is a bit thick even for me.

BJU offers open access to Leslie 2007.  After I compiled the trail of papers that made this error possible – I asked to review the draft of the new chapter on vasectomy.  That was October 1.

Here’s the response:  “ would be highly inappropriate to provide a draft chapter prior to the text being published.

Screw you Elsevier.

Cutting and pasting from German is hard

Sometimes people mess up translations.

Maybe it’s the gutteral sounds of German.

Medline incorrectly got the lower bound of chronic pain post vasectomy as 0.5% when it should be 3%.  Here’s the correction I’ve filed with Pubmed and the original full text (in German).

PubMed link:

You can find the data in Table 2.

PMID:  21845426
TITLE: Ischemic testicular necrosis following vasectomy: rare and typical complications of an outpatient procedure
TEXT: Late complications are chronic pain (0.5-18%), pain during sex (2.9%), hydrocele (0-4%) as well as spermatocele (1.6%)
CORRECTION: Late complications are chronic pain (3-18%), pain during sex (2.9-5%), hydrocele (0-4%) as well as spermatocele (1.6%)
NOTE:  The data in question is in Table 2 on the fourth page. I’ve attached the article for your reference.

Original journal article:  Ischemic testicular necrosis following vasectomy: rare and typical complications of an outpatient procedure

Silver linings

So I was going to post more, but life happened.

This is going to be a short one.

Despite PVPS taking up more of my attention than I’d like, lots of other things have been really great this year.

The kids are getting smart. Possibly too smart. 

Rosie is picking up piano at a startling pace. I think the kid has some natural talent there.

I also decided to get some exercise starting in May.  I’ve since shed 4 inches off the waist and gained enough strength to be doing double handed exercises with 45lb kettle bells. 

Parallette work is coming along, I can almost do a proper L-sit, and running 5-7km is pretty easy for me now.  Not too shabby for a former couch potato.

Have a great year everyone!