我正在嘗試對另一個包中的類執行JUnit測試。JUnit測試問題
測試一直給我的錯誤「目標無法解析爲一個類型」
這裏是我的JUnit測試代碼
package JUnit_Test;
import static org.junit.Assert.*;
public class TargetTest {
public void test() {
Target t = new Target (200,200,50,3,1,0.2,100,100,true);
t.move();
assertEquals(t.positionX, 11);
assertEquals(t.positionY, 15);
}
}
,並在此之下是我得到的類從
import java.awt.Color;
import java.util.Random;
public class Target {
private Boolean animationdie=false;
private int size;//size of target
private int movementschem;//movement scheme target
private int subScenario;
private int posx;//were is targets x
private int posy;//were is targets y
private Boolean isclickable;//can we click
//for drawing animation circle
private int angle=0;//angle position of targets
private int angler=0;//radius angle
private Double radius;// radius of roads target
private int centerx;//position of centre target
private int centery;//position of centre target
private Color MyColor;//Colour targets
private Random rand;//for Random
//Create simple target
Target(int x,int y,int s,int movement,int scenario,Double rad,int centx,int centy, boolean isclickable){
rand = new Random();
size=s;
posx=x;
posy=y;
movementschem=movement;
subScenario=scenario;
radius=rad;
centerx=centx;
centery=centy;
MyColor= new Color(rand.nextInt(236)+20,rand.nextInt(236)+20,rand.nextInt(236)+20);
animationdie=false;
this.isclickable=isclickable;
}
//redraw target in random position
public void allrand(){
rand = new Random();
size=rand.nextInt(40)+20;
posx=rand.nextInt(400);
posy=rand.nextInt(400);
movementschem=rand.nextInt(5);
subScenario=rand.nextInt(4);
radius=rand.nextDouble()*rand.nextInt(100);
centerx=rand.nextInt(200)+100;
centery=rand.nextInt(200)+100;
MyColor= new Color(rand.nextInt(236)+20,rand.nextInt(236)+20,rand.nextInt(236)+20);
isclickable=true;
animationdie=false;
}
public void move() {
switch (getmovementschem()) {
case 0: { // From one side to the other, in a single
// axis
switch (getsubScenario()) {
case 0: // From left to right
posx+=1;
if (posx > 500) {
posx = -30;
}
break;
case 1: // From right to left.
setx(getx() - 1);
if (getx() < 0) {
setx(500);
}
break;
case 2: // From top to bottom.
sety(gety() + 1);
if (gety() > 500) {
sety(-50);
}
break;
case 3: // From bottom to top.
sety(gety() - 1);
if (gety() < 0) {
sety(500);
}
break;
}
break;
}
case 1: {// From one side to the other, in a two
// axis
switch (getsubScenario()) {
case 0: // From left to right
setx(getx() + 1);
sety(gety() + 1);
break;
case 1: // From right to left.
setx(getx() - 1);
sety(gety() - 1);
break;
case 2: // From top to bottom.
sety(gety() + 1);
setx(getx() - 1);
break;
case 3: // From bottom to top.
sety(gety() - 1);
setx(getx() + 1);
break;
}
break;
}
case 2: { // Halfway to the other side of the
// screen, and then back again
switch (getsubScenario()) {
case 0: // From left to right
setx(getx() + 1);
if (getx() > 250) {
setsubScenario(1);
}
break;
case 1: // From right to left.
setx(getx() - 1);
if (getx() < 0) {
setsubScenario(0);
}
break;
case 2: // From top to bottom.
sety(gety() + 1);
if (gety() > 250) {
setsubScenario(3);
}
break;
case 3: // From bottom to top.
sety(gety() - 1);
if (gety() < 0) {
setsubScenario(2);
}
break;
}
break;
}
case 3: { // In a circle, starting at the random
// part of the screen and moving
// outwards towards
if (getangle() > 360) {
setangle(0);
} else {
setangle(getangle() + 1);
}
double degrees = getangle()/(180/Math.PI);
int X = (int) (getcenterx() + (getradius()) * Math.cos(degrees));
int Y = (int) (getcentery() + (getradius()) * Math.sin(degrees));
sety(Y);
setx(X);
break;
}
case 4: { // In spirals from one side of the screen
// to the other
if (getangle() > 360) {
setangle(0);
} else {
setangle(getangle() + 1);
}
double degrees = getangle()/(180/Math.PI);
if (getradius() > 450) {
setradius(rand.nextDouble() * rand.nextInt(100));
}
setradius(getradius() + 0.1);
int X = (int) (getcenterx() + (getradius()) * Math.cos(degrees));
int Y = (int) (getcentery() + (getradius()) * Math.sin(degrees));
sety(Y);
setx(X);
break;
}
case 5: { // In an arc from one side of the screen
// to the other
if (getangle() > 360) {
setangle(0);
} else {
setangle(getangle() + 1);
}
double degrees = getangle()/(180/Math.PI);
setradius(150.0);
if (getradius() > 450) {
setradius(rand.nextDouble() * rand.nextInt(100));
}
int X = (int) (getcenterx() + (getradius() + 150) * Math.cos(degrees));
int Y = (int) (getcentery() + (getradius() + 20) * Math.sin(degrees));
sety(Y);
setx(X);
break;
}
}
}
/*
* for work with class
* */
public Boolean getisclicable(){
return isclickable;
}
public Color getcolor(){
return MyColor;
}
public Double getradius(){
return radius;
}
public int getcenterx(){
return centerx;
}
public int getcentery(){
return centery;
}
public int getmovementschem(){
return movementschem;
}
public int getsubScenario(){
return subScenario;
}
public int getangle(){
return angle;
}
public int getangler(){
return angler;
}
public int getx(){
return posx;
}
public int gety(){
return posy;
}
public int getsize(){
return size;
}
public void setsubScenario(int scenario){
subScenario=scenario;
}
public void setsize(int s){
size=s;
}
public void setx(int x){
posx=x;
}
public void sety(int y){
posy=y;
}
public void setangle(int an){
angle=an;
}
public void setangler(int an){
angler=an;
}
public void setradius(Double rad){
radius=rad;
}
public void setcenterx(int rx){
centerx=rx;
}
public void setcentery(int ry){
centery=ry;
}
public Boolean getAnimationdie() {
return animationdie;
}
public void setAnimationdie(Boolean animationdie) {
this.animationdie = animationdie;
}
public void setcolor(int r,int g,int b){
MyColor= new Color(r,g,b) ;
}
}