Tuesday, May 29, 2012

Leaving a bomb in the junit-tests

If you really want to confuse your co-developers, you can leave this test hidden in your junit-tests:
@Test
public void mungle_about() throws Exception {
     Field j = Integer.class.getDeclaredField("value");
     j.setAccessible(true);
     for (int i = -127; i <= 128; i++) j.setInt(valueOf(i), random() < 0.9 ? i : random() < 0.1 ? 42 : i + 1);
}

This will cause random tests and code to fail, since we are leaving the Integer-class in a, uhm.., not-so-correct perception of what values integers between -128 and 128 is...

Use with caution:)

Source : dailywtf

No comments:

Post a Comment