简体   繁体   中英

IntelliJ - How to include @Test annotation in file template

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 () {      

}
}

在测试文件模板中静态导入了“ org.testng.annotations.Test”。

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() {

    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM