java - 测试继承的构造函数时出现类型不匹配错误
问题描述
我正在使用日食。当我尝试使用 Junit 测试一个类时,在尝试创建对象时出现错误。
public abstract class Property {
private int number = 0;
private String street = null;
private String city = null;
private String postCode = null;
private int numberOfRooms = 0;
public Property(int number, String street, String city, String postCode, int numberOfRooms) {...}
...
}
public class House extends Property {
public House(int number, String street, String city, String postCode, int numberOfRooms) {
super(number, street, city, postCode, numberOfRooms);
}
...
}
这是junit测试文件:
public class PropertyTest {
@Test
public void testHouse() {
Property house = new House(1, "Percy Road", "London", "WC2N 5DU", 2);
assertEquals("1 Percy Road, London WC2N 5DU (2 bedroom house)", house.toString());
}
}
我在 PropertyTest: Type mismatch: cannot convert from House to Property中得到这个错误。据我所知,这段代码应该可以工作
解决方案
推荐阅读
- speech-recognition - 有没有办法使用 HTK 获得单音素概率?
- amazon-web-services - 如何修复 DynamoDB JS API 阻塞和超时我的 Lambda 函数?
- java - 修改后的 N 皇后与放置的皇后
- react-native - 如何使 ScrollView 仅在 React Native 中的子大小较大时滚动
- aws-glue - JSON ISO 8601 时间字符串到时间格式 AWS-Glue
- javascript - 在 Sequelize 中创建此 SQL
- asp.net - 使用数据阅读器选择和显示数据的问题
- amazon-ec2 - CloudFront 和一个 EC2 源之间的连接如何使用 HTTPS 工作?
- node.js - express.js 请求事件是否记录在任何地方?
- docker - Docker 组合和外部图像多阶段构建