我试着根据这个例子(https://github.com/21decemb/spring-boot-dbunit-example)为我的数据库服务编写单元测试。我创建了数据集和测试示例。运行测试后,我收到了:org.dbunit.dataset.NoSuchTableException: orders
dataset.xml:
<?xml version="1.0" encoding="UTF-8"?>
<dataset>
<!-- CUSTOMER DATA -->
<customers id="1" name="Customer" active="1"/>
<!-- POSITION DATA -->
<positions id="1" name="POSITION1"/>
<positions id="2" name="POSITION2"/>
<positions id="3" name="POSITION3"/>
<!-- ORDER DATA -->
<orders id="1" name="order1" color="RED" express="0" date="2016-12-11 19:47:39" last_update="2016-12-11 19:47:39" parent_id="1" active="1"/>
<!--<orders id="2" name="order2" color="WHITE" customer_id="1" position_id="1" express="0" date="2016-12-11 19:47:39" last_update="2016-12-11 19:47:39" active="0"/>-->
</dataset>因为我测试了两种可能性,所以对二阶行进行了评论。我知道这是因为加入。当我只测试“位置”和“客户”(没有联接的简单实体)时,它正确工作。
我的“命令”实体:
@Entity
@Table(name = "orders", schema = Config.dbSchema)
public class Order implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private long id;
private String name;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name="POSITION_ID")
private Position position;
private short express;
private Date date;
@Column(name="LAST_UPDATE")
private Date lastUpdate;
@Column(name="parent_id")
private Long parentId;
private short active;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name="CUSTOMER_ID")
private Customer customer;
@OneToMany(mappedBy = "order", fetch = FetchType.LAZY)
private List<Component> components;
//getters and setters
}有谁知道怎么解决它吗?
提前谢谢。
发布于 2016-12-23 10:35:36
必须在覆盖方法setUpDatabaseConfig中添加此属性。
@Override
protected void setUpDatabaseConfig(DatabaseConfig config) {
config.setProperty(DatabaseConfig.FEATURE_QUALIFIED_TABLE_NAMES, true);
}此外,您可能需要添加模式名如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<dataset>
<!-- CUSTOMER DATA -->
<schemaName customers id="1" name="Customer" active="1"/>
<!-- POSITION DATA -->
<schemaName positions id="1" name="POSITION1"/>
<schemaName positions id="2" name="POSITION2"/>
<schemaName positions id="3" name="POSITION3"/>
<!-- ORDER DATA -->
<schemaName orders id="1" name="order1" color="RED" express="0" date="2016-12-11 19:47:39" last_update="2016-12-11 19:47:39" parent_id="1" active="1"/>
<!--<schemaName orders id="2" name="order2" color="WHITE" customer_id="1" position_id="1" express="0" date="2016-12-11 19:47:39" last_update="2016-12-11 19:47:39" active="0"/>-->
</dataset>https://stackoverflow.com/questions/41251302
复制相似问题