English 中文(简体)
Combining JBehave with SpringJUnit4ClassRunner
原标题:Combining JBehave with SpringJUnit4ClassRunner to enable transaction rollback

<<>Esssence:

• 如何在日美特州进行的原始交易 测试JBehave?

问题似乎是,JBehave想要的是SpringAnnotated。 EmbedderRunner,但指出测试为@ Transactional 要求SpringJUnit4ClassRunner

Ive试图找到一些文件,说明如何执行<代码>的滚动,或利用<代码>进行脱色。 SpringJUnit4ClassRunner,但我无法工作。

Does anyone have a (preferably simple) setup that runs JBehave storries with Spring and Hibernate and transaction auto-rollback?



www.un.org/spanish/ecosoc 关于我至今的设置的进一步信息:

JBeact with Spring - but not with autorollback:

@RunWith(SpringAnnotatedEmbedderRunner.class)
@Configure(parameterConverters = ParameterConverters.EnumConverter.class)
@UsingEmbedder(embedder = Embedder.class, generateViewAfterStories = true, ignoreFailureInStories = false, ignoreFailureInView = false)
@UsingSpring(resources = { "file:src/main/webapp/WEB-INF/test-context.xml" })
@UsingSteps
@Transactional // << won t work
@TransactionConfiguration(...) // << won t work
// both require the SpringJUnit4ClassRunner 

public class DwStoryTests extends JUnitStories {

    protected List<String> storyPaths() {

        String searchInDirectory = CodeLocations.codeLocationFromPath("src/test/resources").getFile();
        return new StoryFinder().findPaths(searchInDirectory, Arrays.asList("**/*.story"), null);
    }

}

在我的测试步骤中,我可以@ Inject everything:

@Component
@Transactional // << won t work
public class PersonServiceSteps extends AbstractSmockServerTest {

    @Inject
    private DatabaseSetupHelper databaseSetupHelper;

    @Inject
    private PersonProvider personProvider;

    @Given("a database in default state")
    public void setupDatabase() throws SecurityException {
        databaseSetupHelper.createTypes();
        databaseSetupHelper.createPermission();
    }

    @When("the service $service is called with message $message")
    public void callServiceWithMessage(String service, String message) {
        sendRequestTo("/personService", withMessage("requestPersonSave.xml")).andExpect(noFault());
    }

    @Then("there should be a new person in the database")
    public void assertNewPersonInDatabase() {
        Assert.assertEquals("Service did not save person: ", personProvider.count(), 1);
    }

(即数据库SetupHelper方法均为交易)

个人资料基本上围绕<条码>org.childrenframework.data.jpa.repository.support.SimpleJpaRepository。 因此,可以接触实体 管理者,但控制交易(开工/开工)时,我猜测,因为所有<条码>@Transactional都是在这个助手队伍内进行的。

我也读到,JBehave在一种不同的背景下运行? 届会 什么? 试验开始的交易失去控制吗? 混淆不清。


<<>strong>edit:

above上上述职位,以反映我目前的知识,缩短整个时间,使问题变得更明显,而设置则不那么明显。

最佳回答

我认为,你可以ski露天,为JBehave yourself提供必要的配置。 例如,

@UsingEmbedder(embedder = Embedder.class, generateViewAfterStories = true, ignoreFailureInStories = false, ignoreFailureInView = false)

页: 1

configuredEmbedder()
.embedderControls()
.doGenerateViewAfterStories(true)
.doIgnoreFailureInStories(false)
.doIgnoreFailureInView(false);

Besides: why do you want to rollback the transaction? Typically you are using JBehave for acceptance tests, which run in a production-like environment. For example you first setup some data in the database, access it via Browser/Selenium and check for the results. For that to work the DB transaction has to be committed. Do you need to clean-up manually after your tests, which 页: 1 in @AfterStories or @AfterScenario annotated methods.

问题回答

我通过人工控制交易范围,在每一种假设情景之后将其重新引入。 仅遵循官方指南,说明如何与JBehave一起使用春天,然后做如下所示的trick。

@Component
public class MySteps
{
    @Autowired
    MyDao myDao;

    @Autowired
    PlatformTransactionManager transactionManager;

    TransactionStatus transaction;

    @BeforeScenario
    public void beforeScenario() {
        transaction = transactionManager.getTransaction(new DefaultTransactionDefinition());
    }

    @AfterScenario
    public void afterScenario() {
        if (transaction != null)
            transactionManager.rollback(transaction);
    }

    @Given("...")
    public void persistSomething() {
        myDao.persist(new Foo());
    }
}

我不熟悉JBehave,但你似乎重新寻找这一说明。

@TransactionConfiguration(transactionManager = "transactionManager", defaultRollback = true).

你们也可以在考试成绩中确定真实情况。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签