Unit testing 如何在Arquillian测试中使用@UsingDataSet

Unit testing 如何在Arquillian测试中使用@UsingDataSet,unit-testing,jboss-arquillian,Unit Testing,Jboss Arquillian,我在项目中使用@UsingDataSet时遇到问题。 手册中的示例 没用。 我有一个简单的实体: @Entity(name = "game") @Table(name = "game_entity", schema = "graph") @GenericGenerator(name="uuid2", strategy = "uuid2") public class Game implements Serializable { private static final long serialVe

我在项目中使用@UsingDataSet时遇到问题。 手册中的示例 没用。 我有一个简单的实体:

@Entity(name = "game")
@Table(name = "game_entity", schema = "graph")
@GenericGenerator(name="uuid2", strategy = "uuid2")
public class Game implements Serializable {

private static final long serialVersionUID = -4832711740307931146L;
private UUID id;
private String name;

@Id
@GeneratedValue(generator="uuid2")
public UUID getId() {
    return id;
}

public void setId(UUID id) {
    this.id = id;
}

@NotNull
@Column(name = "name", length = 256, nullable = false)
public String getName() {
    return name;
}

public void setName(String name) {
    this.name = name;
}

@Override
public boolean equals(Object value) {
    if (!(value instanceof Game)) {
        return false;
    }
    if (value == this) {
        return true;
    }
    Game obj = (Game) value;
    if (!obj.getId().equals(getId())) {
        return false;
    }
    return true;
}

@Override
public int hashCode() {
    int result = 29;
    result += 29 * (getId() != null ? getId().hashCode() : 0);
    result += 29*(getName() != null ? getName().hashCode() : 0);
    return result;
}
}
和.yml文件

game_entity:
    - id         : d5c58afd-7c99-41bb-ab0a-6357bfddfe14
      name       : Call of Duty
我的测试:

public class MyTest extends Arquillian {

    @PersistenceContext(unitName = "spo")
    private EntityManager em;

    @Test
    @UsingDataSet("datasets/gameDataSet.yml")
    public void testAttribute() {
        System.out.println("Hello world !");
    }

    @Deployment
    public static WebArchive createArchive() {
        WebArchive war = ShrinkWrap
                .create(WebArchive.class, "myTest.war")
                .addAsLibraries(
                        // blah-blah-blah
                )
                .addAsResource("my-persistence.xml", "META-INF/persistence.xml")
                //.addAsResource("datasets/gameDataSet.yml", "datasets/gameDataSet.yml") // do I need to add this to archive ??
                .addAsWebInfResource("META-INF/beans.xml", "beans.xml")
                .setWebXML("web.xml")
                ;
        return war;
    }
}
当我运行这个测试时,我得到了两个“奇怪”的例外。 有时:

Caused by: org.dbunit.dataset.NoSuchColumnException: game_entity.ID -  (Non-uppercase input column: id) in ColumnNameToIndexes cache map. Note that the map's column names are NOT case sensitive.
但数据库中有两列!“id”和“名称”

有时,更奇怪的例外是:

Caused by: org.postgresql.util.PSQLException: ERROR: relation "info_resource_attributes" does not exist
这是另外两个实体的交叉表,它存在于archive和myPersistence.xml中,但我在本测试中不使用它们。 我使用Wildfly 10和Postgres 9.5。没有@UsingDataSet,一切都很好。 但我不希望在这样的测试中使用programmaticaly硬代码数据:

Entity newEntityForTest = new Entity();
newEntityForTest.setA(...);
newEntityForTest.setB(...);
newEntityForTest.setC(...);
em.persist(newEntityForTest);
// testing ...
em.remove(newEntityForTest);

您使用的是哪个版本的postgresql?这是我对Postgres 9.3的配置-