我尝试根据此示例(https://github.com/21decemb/spring-boot-dbunit-example)为我的数据库服务编写单元测试。我创建了数据集和测试示例。运行测试后,我收到:org.dbunit.dataset.NoSuchTableException: orders
数据集.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
}
有没有人知道如何解决它?
提前致谢。