Question

I am attempting to create a file template in IntelliJ for test classes (TestNG) and I want the @Test annotation to be included in the template. If I use the fully qualified namespace for the annotation it does work, however, I would prefer the tests only have the @Test annotation. When I use the full annotation it ends up looking like this:

@org.testng.annotations.Test
public void testGeneratedStub () {      

}

I would prefer that it look like this:

@Test
public void testGeneratedStub () {      

}

I have tried using @Test in the template while also adding the import statement "import org.testng.annotations.Test;" but that also does not work. Has anyone been able to get this to work?

Edit I tried the static import as suggested by Rafik991 like the code below but I still end up with the fully qualified annotation (also tried just @Test with the static import):

#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end
import static org.testng.annotations.Test;
#parse("File Header.java")
public class ${NAME} extends TestBase { 

@org.testng.annotations.Test
public void testGeneratedStub () {      

}
}
Was it helpful?

Solution

Here's what the template should look like to work:

#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end
#parse("File Header.java")
import org.testng.annotations.Test;
public class ${NAME} {
    @Test
    public void testGeneratedStub () {      
        $END$
    }
}

Result:

/**
 * User: demo
 * Date: 2/7/14
 * Time: 11:02 AM
 */

import org.testng.annotations.Test;

public class StackoverflowTest {
    @Test
    public void testGeneratedStub() {

    }
}

OTHER TIPS

Made static import of "org.testng.annotations.Test" in test file template.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top