My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for
BadCodeSnippetsRunner  
bad code snippets is meta-test to avoid bad behaviors
Updated May 1, 2010 by pascallo...@gmail.com

We used to hear things like "Oh yeah, you're not supposed to use assertEquals with BigDecimal" all the time in our office. Over time, like any engineering organization would do, we documented all the traps and pitfalls of clumsy APIs, odd patterns and such that we dealt with daily due to third-party integration. We even made it part of the new hire on boarding process.

The team grew. And old timers would still spend as much time mentoring, fixing "obvious" bugs and running after production stack traces.

Motivating Example

Introducing BadCodeSnippetsRunner. Let's start with a motivating example.

@RunWith(BadCodeSnippetsRunner.class)
@CodeSnippets({
    @Check(paths = "src/com/kaching", snippets = {
        // no uses of java.net.URL
        @Snippet("\\bjava\\.net\\.URL\\b"),

       // no System.out.print, instead log
       @Snippet(value = "\\bSystem\\.out\\.print", exceptions = {
            "src/com/kaching/MainEntryPoint.java",
            "src/com/kaching/LoadTestingHarness.java"})
    })
})
public class BadCodeSnippetsTest {
}

Here, we declaratively create a bad code snippets test to ensure that the evil URL class is never used in the code base. Similarly, it guarantees that only MainEntryPoint and LoadTestingHarness use System.out.print.


Sign in to add a comment
Powered by Google Project Hosting