我尝试根据此示例(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>
第二个Order Row被评论,因为我正在测试两种可能性。我知道这是因为加入。当我只测试'位置'和'客户'(没有连接的简单实体)时,它可以正常工作。
我的“订单”实体:
@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
}
有没有人知道如何修复它?
提前致谢。
答案 0 :(得分:0)
您必须在覆盖方法 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>