我想将现有的JUnit4-Tests与Powermockito一起迁移到我的Gradle-Project中。
package test_junit;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import game_editor.lwjgl.impl.LWJGLQuad;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.lwjgl.opengl.GL11;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import sr.util.Color;
import sr.util.Position;
import sr.util.Size;
@RunWith(PowerMockRunner.class)
@PrepareForTest(
{ GL11.class })
public class TestLWJGLQuad
{
private final int sizeY = 3;
private final int sizeX = 2;
private final int y = 1;
private final int x = 0;
private final int positionY = 9;
private final int positionX = 8;
@Test
public void teste_print()
{
PowerMockito.mockStatic(GL11.class);
LWJGLQuad quad = getQuad();
quad.print(new Position(positionX, positionY));
verify();
}
private void verify()
{
PowerMockito.verifyStatic();
GL11.glColor4f(red, green, blue, alpha);
PowerMockito.verifyStatic();
GL11.glVertex2f(x + positionX, y + positionY);
PowerMockito.verifyStatic();
GL11.glVertex2f(x + positionX + sizeX, y + positionY);
PowerMockito.verifyStatic();
GL11.glVertex2f(x + positionX + sizeX, y + positionY + sizeY);
PowerMockito.verifyStatic();
GL11.glVertex2f(x + positionX, y + positionY + sizeY);
PowerMockito.verifyStatic();
GL11.glEnd();
}
}
gradle-File:
apply plugin: 'java'
apply plugin: 'application'
def applicationName = "game_editor"
sourceCompatibility = 1.7
version = '1.0'
mainClassName = "demo.DemoSzene3Gaming"
def junitversion = '4.+'
def powermockitoversion = '1.+'
def lwjglversion = "2.+"
repositories {
mavenCentral()
jcenter()
}
dependencies {
compile group: 'org.lwjgl.lwjgl', name: 'lwjgl', version: lwjglversion
testCompile group: 'junit', name: 'junit', version: junitversion
testCompile group: 'org.powermock', name: 'powermock-module-junit4', version: powermockitoversion
testCompile group: 'org.powermock', name: 'powermock-api-mockito', version: powermockitoversion
}
Gradle构建完美,没有错误,Test-Classes没有编译错误,所有依赖项都在Build-Path中。但在我的src / test / java中,我无法在编辑器中引用任何导入的jar类。所有引用都带有红色下划线。 通常JUnit-Test也不会工作。
为什么会这样?