如何解决java.sql.DriverManager未准备好进行测试
我有一个测试,它引发以下错误。
n >= 1
我已将测试最小化为以下代码以缩小范围
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.powermock.reflect.internal.WhiteboxImpl to method java.lang.Object.clone()
WARNING: Please consider reporting this to the maintainers of org.powermock.reflect.internal.WhiteboxImpl
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
org.powermock.api.mockito.ClassNotPreparedException:
[Ljava.lang.Object;@383caf89
The class java.sql.DriverManager not prepared for test.
这是我pom.xml中的依赖项
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.*;
import org.mockito.junit.MockitoJUnitRunner;
import com.microsoft.azure.functions.*;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import java.sql.*;
import java.util.logging.Logger;
import static org.mockito.Mockito.*;
@RunWith(PowerMockRunner.class)
@PrepareForTest({DriverManager.class,ClassCallingDriverManager.class})
public class ClassCallingDriverManagerTest{
@Test
public void testMethod() throws SQLException {
final Connection connection = mock(Connection.class);
PowerMockito.mockStatic(DriverManager.class);
}
}
我不知道是什么原因导致了我的mockStatic()错误。我这样做对吗?我正在尝试测试DriverManager.getConnection()方法,但该调用始终失败,因此我删除了代码,直到将其范围缩小到这一行。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。