为了减少单个类中的测试数量,我正在使用NUnits TestCase
属性将多个测试用例提供给单个测试方法。
但是,我的每个测试的输出都会有所不同,具体取决于哪个测试用例参数使测试失败。例如,如果测试用例为"street", "town$", "state"
,而在测试中是town
由于存在符号而失败,则字符串town is invalid
将由被测试的方法返回。 / p>
但是,如果下一个TestCase
是"street$", "town", "state"
,则返回的字符串将是street is invalid
。
我需要一种方法来确定测试方法在单个时间点正在执行哪个TestCase。在NUnit中有什么可能的方法?
我确实有一个想法,即将变量和TestCase参数一起传入,该变量会改变每种情况,例如:
"street1", "town1", "state1", 1 // <-- this int changes with each test case
"street2", "town2", "state2", 2
"street3", "town3", "state3", 3
但是,这似乎是一种非常棘手的工作方式,是否有更好的选择?
答案 0 :(得分:0)
我将添加第四个参数,表示要测试的方法的预期收益:
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.image.BufferStrategy;
import javax.swing.JPanel;
public class Game extends JPanel implements Runnable{
private static final long serialVersionUID = 1L;
public static final int width = 1024, height = 576;
private boolean running = false;
private Thread thread;
private Handler handler;
public Game(){
handler = new Handler();
new Frame(width, height, "My Game :)", this);
Start();
handler.addObject(new Background(0, 0, width, height, ID.Hud));
handler.addObject(new Ball(675, 0, 30, 30, ID.Ball, handler));
handler.addObject(new Paddle(width-50,height/2-38,10,50,ID.PaddleB));
this.addKeyListener(new KeyInput(handler));
}
private void Start(){
running = true;
thread = new Thread(this);
thread.start();
}
private void Stop(){
running = false;
try {
thread.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
public void run(){
this.requestFocus();
long lastTime = System.nanoTime();
double amountOfTicks = 60.0;
double ns = 1000000000 / amountOfTicks;
double delta = 0;
long timer = System.currentTimeMillis();
long now;
int frames = 0;
while (running) {
now = System.nanoTime ();
delta += (now - lastTime) / ns;
lastTime = now;
while (delta >= 1) {
tick();
delta--;
}
render();
frames++;
if (System.currentTimeMillis () - timer > 1000) {
timer += 1000;
System.out.println(frames);
frames = 0;
}
}
}
public void tick(){
handler.tick();
}
public void render(){
BufferStrategy bs = this.getBufferStrategy(); //<--This is where the error is found
Graphics g = bs.getDrawGraphics();
Graphics2D g2d = (Graphics2D) g;
handler.render(g);
g.dispose();
bs.show();
}
public static void main(String args[]) throws InterruptedException{
new Game();
}
}