天天看点

idea Maven项目进行Junit 单元测试使用junit单元测试,报Cannot instantiate test(s): java.lang.SecurityException: Prohibited package name: java.com.com.test

idea Maven项目进行Junit 单元测试使用junit单元测试,报Cannot instantiate test(s): java.lang.SecurityException: Prohibited package name: java.com.com.test
idea Maven项目进行Junit 单元测试使用junit单元测试,报Cannot instantiate test(s): java.lang.SecurityException: Prohibited package name: java.com.com.test
idea Maven项目进行Junit 单元测试使用junit单元测试,报Cannot instantiate test(s): java.lang.SecurityException: Prohibited package name: java.com.com.test
idea Maven项目进行Junit 单元测试使用junit单元测试,报Cannot instantiate test(s): java.lang.SecurityException: Prohibited package name: java.com.com.test
idea Maven项目进行Junit 单元测试使用junit单元测试,报Cannot instantiate test(s): java.lang.SecurityException: Prohibited package name: java.com.com.test

2  项目设置

idea Maven项目进行Junit 单元测试使用junit单元测试,报Cannot instantiate test(s): java.lang.SecurityException: Prohibited package name: java.com.com.test
idea Maven项目进行Junit 单元测试使用junit单元测试,报Cannot instantiate test(s): java.lang.SecurityException: Prohibited package name: java.com.com.test

3安装插件 对应三个插件

idea Maven项目进行Junit 单元测试使用junit单元测试,报Cannot instantiate test(s): java.lang.SecurityException: Prohibited package name: java.com.com.test
idea Maven项目进行Junit 单元测试使用junit单元测试,报Cannot instantiate test(s): java.lang.SecurityException: Prohibited package name: java.com.com.test
idea Maven项目进行Junit 单元测试使用junit单元测试,报Cannot instantiate test(s): java.lang.SecurityException: Prohibited package name: java.com.com.test

4 测试

idea Maven项目进行Junit 单元测试使用junit单元测试,报Cannot instantiate test(s): java.lang.SecurityException: Prohibited package name: java.com.com.test

5 在当前的类按快捷键

idea Maven项目进行Junit 单元测试使用junit单元测试,报Cannot instantiate test(s): java.lang.SecurityException: Prohibited package name: java.com.com.test

6 添加需要测试的方法

idea Maven项目进行Junit 单元测试使用junit单元测试,报Cannot instantiate test(s): java.lang.SecurityException: Prohibited package name: java.com.com.test

使用junit单元测试,报Cannot instantiate test(s): java.lang.SecurityException: Prohibited package name: java.com.com.test

在测试类中不能一级包名不能以java开头,

将包改为com.test就好了

idea Maven项目进行Junit 单元测试使用junit单元测试,报Cannot instantiate test(s): java.lang.SecurityException: Prohibited package name: java.com.com.test

7 ctrl+shit+f10 执行demoTest

idea Maven项目进行Junit 单元测试使用junit单元测试,报Cannot instantiate test(s): java.lang.SecurityException: Prohibited package name: java.com.com.test

完成以后报错java.lang.ClassNotFoundException: org.hamcrest.SelfDescribing

少了hamcrest-core-1.3.jar包

下载地址https://mvnrepository.com/

https://mvnrepository.com/artifact/org.hamcrest/hamcrest-core/1.3

idea Maven项目进行Junit 单元测试使用junit单元测试,报Cannot instantiate test(s): java.lang.SecurityException: Prohibited package name: java.com.com.test
idea Maven项目进行Junit 单元测试使用junit单元测试,报Cannot instantiate test(s): java.lang.SecurityException: Prohibited package name: java.com.com.test