无法使用Ejb3Unit进行测试

时间:2011-10-07 08:55:01

标签: java testing

我从Ejb3Unit下载了示例项目,将其导入eclipse并将其作为JUnit Test运行 - >没有错误。

但是当我尝试测试自己的实体类时,我总是得到一个OutOfMemoryError!

@Entity
@Table(name = "AUTOR")
public class Author implements Serializable {

private int id; 
private String name;    
private Date created;

@Id
@GeneratedValue
public int getId() {
    return id;
}

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

public String getName() {
    return name;
}

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

@Column(name = "creation_timestamp", nullable = false)
public Date getCreated() {
    return created;
}

public void setCreated(Date created) {
    this.created = created;
}   
}


public class AuthorTest extends BaseEntityFixture<Author> { 

public AuthorTest() {
    super(Author.class);
}   
}

java.lang.OutOfMemoryError:Java堆空间     at java.util.Arrays.copyOf(Arrays.java:2882)     at java.lang.AbstractStringBuilder.expandCapacity(AbstractStringBuilder.java:100)     at java.lang.AbstractStringBuilder.append(AbstractStringBuilder.java:572)     在java.lang.StringBuilder.append(StringBuilder.java:203)     at com.bm.datagen.utils.BaseRandomDataGenerator.getValueString(BaseRandomDataGenerator.java:109)     at com.bm.datagen.random.RandomStringGenerator.getValue(RandomStringGenerator.java:45)     at com.bm.datagen.random.RandomStringGenerator.getValue(RandomStringGenerator.java:20)     在com.bm.datagen.DataGenerator.getNextValue(DataGenerator.java:127)     在com.bm.creators.EntityInstanceCreator.createInstance(EntityInstanceCreator.java:91)     在com.bm.creators.EntityBeanCreator.createBeanInstance(EntityBeanCreator.java:113)     在com.bm.testsuite.BaseEntityFixture.testWrite(BaseEntityFixture.java:182)     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)     在java.lang.reflect.Method.invoke(Method.java:597)     在junit.framework.TestCase.runTest(TestCase.java:154)     在org.jmock.core.VerifyingTestCase.runBare(未知来源)     在junit.framework.TestResult $ 1.protect(TestResult.java:106)     在junit.framework.TestResult.runProtected(TestResult.java:124)     在junit.framework.TestResult.run(TestResult.java:109)     在junit.framework.TestCase.run(TestCase.java:118)     在junit.framework.TestSuite.runTest(TestSuite.java:208)     在junit.framework.TestSuite.run(TestSuite.java:203)     在org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)     在org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)     在org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)     在org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)     在org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)     在org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

我是否必须在任何属性文件中进行一些更改,或者其他地方是否存在问题?

1 个答案:

答案 0 :(得分:2)

增加eclipse的-Xmx配置值(例如在eclipse.ini中)应该会有所帮助。

有关详细信息,请参阅:

http://wiki.eclipse.org/FAQ_How_do_I_increase_the_heap_size_available_to_Eclipse%3F

问题可能与随机字符串的大小有关,ejb3unit用于自动测试您的实体bean,尝试更改@Column(length = ...)

长度的默认值是255,这不是一个整数。