2016-11-21 48 views
0

我試圖用黃瓜寫以下數據庫測試:播放2.5.9 +黃瓜JPA withTransaction棄用

@Given("^I have N foos$") 
public void i_have_N_foos() throws Throwable { 
    JPA.withTransaction(() -> { 
     fooSize = foo.count(); 
    }); 
} 

foot.count()應在交易,但JPA.withTransaction方法已過時。如何在我的黃瓜測試中使用JPAApi

+0

我還沒有和黃瓜的工作,但,你應該能夠'@注入JPAApi'到您的測試。 –

回答

0

修正了:

public class Foo{ 

JPAApi jpaApi; 

@Given("^I have N foos$") 
public void i_have_N_foos() throws Throwable { 
jpaAPI= JPA.createFor("fooPersistenceUnit"); 
jpaApi.withTransaction(() -> { 
    fooSize = foo.count(); 
}); 
} 

}