IDEA14: How to create linked documentation for JUnit test cases

Hi,

When I write my JUnit test cases I like them to look like:

public class MyClassTest {
/**
* Unit test {@link MyClassTest#myMethod}
*/
@Test
public void
testMyMethod() {

}

}


The important bit is the generated JavaDoc which contains a link to the method under test which I can use the link to quickly bring up the JavaDocs of the method under test.

Is there anyway to automate the generation of the link? I can see that the "JUnit4 Test Method" has a variable called ${NAME} (which rather anoyingly starts with an UPPER case letter), but I don't see anything in that template that gives me the class name for my hyperlink.

Cheers

4 comments
Comment actions Permalink

Hi John,

it's possible to generate reference on tested class with ${CLASS_NAME} if you generate test class for class (Ctrl-Shift-T); when you generate new test method in the existing class, there is no class which you test (names search could be wrong/produce many results), thus the class name is not available.

Anna

0
Comment actions Permalink

Hi Anna,

I've set up the following templates:

JUnit Test Class

#parse("File Header.java")

#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end


import org.junit.Assert;
import org.junit.Test;

/**
* Unit test for {@link ${CLASS_NAME}}
*/
public class ${NAME} {
  ${BODY}
}

JUnit4 Test Method

/**
  * Unit test {@link ${CLASS_NAME}#${NAME}}
  */
@org.junit.Test
public void test${NAME}() {
  ${BODY}
}


however when the class is first generated all I get is:

/**
* Unit test for {@link MyClass}
*/
public class MyClassTest {

    /**
     * Unit test {@link ${CLASS_NAME}#MyMethod}
     */
    @Test
    public void
testMyMethod() {

    }
}



So it appears that JUnit Test Class is being expanded correctly, but JUnit4 Test Method is inserting the literal text "${CLASS_NAME}"

0
Comment actions Permalink

Hi John,

that's possible to fix. Will do it ASAP.

Thanks,
Anna

0
Comment actions Permalink

Thank you   :-)


0

Please sign in to leave a comment.