May 2010

Make Fireworks IntelliJ Plugin Ignore Integration Tests


http://www.wafermaneuver.com/nick/img/photo/fireworks2.jpg

The Fireworks Plugin for IntelliJ allows you to automatically run all your unit tests when you make a change to the code.

Its a well behaved plugin, it allows you to configure wether or not to do this so you can just turn it on or off.

Whilst using it I made a detour to Shave a couple of Yaks. So thought I’d document it here.

I found it was also running some integration tests which relied on the file system and so didn’t work because there doesn’t appear to be a way to specify the working directory (you can specify JVM args so I could use that instead. I submitted an issue.

In the mean time, actually I thought I would rather not run my integration tests. Fortunately Fireworks allows a regex pattern to decide which files are tests.

After some hunting, I found the following post on stack overflow which gave me the clues i needed to include Test but not IntegrationTest.

The solution takes advantage of “lookaround” features of regex. The syntax in question is:

(?!Integration)

The (?! regex ) syntax means negative look ahead. You can put any regex in there. In our case, just “Integration”. This says, something not followed by “Integration”.

The code on stack overflow had some unnescessary syntax at the beginning (^) and I changed the ordering around a bit to make it read more logically.

(.(?!Integration))*Test

The first “^” was unnescessary, and putting the “.” first made it read better i think. The parentheses are to provide some structure (regex groups) more than any functional reason.

So in words, the new expression reads “match any repeating character (.*) not followed by “Integration” (?!Integration)), then only match if “Test” is on the end.

Here is a test case for it (which along with some other regex stuff can be found on Github :

    @Test
    public void matchesUnitTestsButNotIntegrationTests() {
        String expression = “(.(?!Integration))*Test”;
        Pattern pattern = Pattern.compile(expression);
        assertThat(pattern.matcher(“SomeUnitTest”).matches(), is(true));
        assertThat(pattern.matcher(“SomeIntegrationTest”).matches(), is(false));
        assertThat(pattern.matcher(“SomeNonTestClass”).matches(), is(false));
    }

I found it hard to get this to work on the command line with grep. But I’ve got too much YAK HAIR on my floor now!

Now the Yaks are shaved I can go back to putting a system property in to allow my integration test to work.

  • Share/Bookmark

code
regex
testing

Comments (0)

Permalink

Link from log console output to a line of code in IntelliJ

Whilst playing around with some code analysis I thought it would be useful to be able to output a hyperlink back to a line of code in the IDE console. As it happens, you can “Trick” IntelliJ to do this with the following log statement:

    @Test
    public void canClickOnAFileInTheConsoleAndGoToTheLineOfCode() {
        log.info(String.format(“Check it at %s. (%s.java:%d)”,
            getClass().getName(), getClass().getSimpleName(), 15));
    }

The pattern it seems to match is something like at {classFullName}.{identifier}({classSimpleName}.java)

classFullName has to be a valid class name.
identifier is usually used for the method name, but it can be anything. The full stop is nescessary. So in the example above, I put a space in there and so it reads like a sentance.

Anyone know a another way to do this?

UPDATE:

Actually it seems that you can get something similar if you output a full path name, e.g.:

    File f = new File(“./src/test/resource/testfiles/level_01/level_01_01/file_01_01_A.txt”);
    log.info(f.getAbsolutePath() + “:” + 34);

This will create a link in the output window to the line of the file. Nice.

  • Share/Bookmark

code
ides
java
thoughtblog

Comments (0)

Permalink