我有一个测试,它引发以下错误。
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()方法,但该调用始终失败,因此我删除了代码,直到将其范围缩小到这一行。