飞机大战英雄机Junit单元测试
时间: 2024-01-31 20:02:57 浏览: 30
由于没有具体的代码实现,以下是一个可能的Junit单元测试用例:
```java
import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class HeroPlaneTest {
// 测试英雄机初始化位置是否正确
@Test
public void testInitPosition() {
HeroPlane heroPlane = new HeroPlane();
assertEquals(200, heroPlane.getX()); // 初始化时x坐标应为200
assertEquals(500, heroPlane.getY()); // 初始化时y坐标应为500
}
// 测试英雄机移动方法是否正确
@Test
public void testMove() {
HeroPlane heroPlane = new HeroPlane();
heroPlane.move(10, 20); // 向右移动10个单位,向下移动20个单位
assertEquals(210, heroPlane.getX()); // 移动后x坐标应为210
assertEquals(520, heroPlane.getY()); // 移动后y坐标应为520
}
// 测试英雄机是否能够发射子弹
@Test
public void testShoot() {
HeroPlane heroPlane = new HeroPlane();
heroPlane.shoot(); // 发射一枚子弹
assertEquals(1, heroPlane.getBullets().size()); // 子弹列表长度应为1
Bullet bullet = heroPlane.getBullets().get(0);
assertEquals(200, bullet.getX()); // 子弹x坐标应与英雄机相同
assertEquals(480, bullet.getY()); // 子弹y坐标应与英雄机头部相同
}
}
```
相关推荐
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)