使用单元测试中Annotations are not allowed here

时间:2025-04-06 13:01:34

Annotations are not allowed here:

刚刚用单元测试中发现报错Annotations are not allowed here


单元测试报错显示Annotations are not allowed here

public class StringTest {

    @Test
    public void test1{

    }

}

先检查了一遍包有没有导错,发现没有错
然后看了一遍前面写的单元测试发现是自己单元测试的方法没有加括号

import org.junit.Test;

加上括号就解决了

public class StringTest {

    @Test
    public void test1(){

    }

}