繁体   English   中英

使用TestFX的TornadoFX在每个TestCase之后关闭View

[英]TornadoFX with TestFX close the View after every TestCase

我试图用testfx框架测试一个基本的登录屏幕(使用tornadofx创建)。

我添加了3个运行正常的测试用例,但问题是它们使用的是前一个阶段而不是创建一个新阶段。 我希望测试用例独立运行。

我正在测试View()而不是App()。 如果我使用MyMainApp()。start(stage)然后使用MyMainApp()。stop(),我会得到所需的行为。
但是如何为视图和片段执行此操作。

以下是代码:

class LoginScreenFeatureTest : ApplicationTest() {

    override fun init() {
        FxToolkit.registerStage { Stage() }
    }

    override fun start(stage: Stage) {
        LoginScreen().openWindow()
        //MyMainApp().start(stage)
    }

    override fun stop() {
        FxToolkit.cleanupStages()
        //FxToolkit.toolkitContext().registeredStage.close()
        //MyMainApp().stop()
    }

    @Test fun should_contain_button() {
        // expect:
        verifyThat("#submitBut", hasText("SUBMIT"))
    }

    @Test fun should_click_on_button_and_pass_login() {
        //init
        //Why do I always need to erase text. I want a new stage for every test case.
        clickOn("#username").eraseText(10).write("validUser")
        clickOn("#password").eraseText(10).write("validPwd")
        clickOn("#orgId").eraseText(10).write("validOrg")

        // when:
        clickOn("#submitBut")

        // then:
        //verify success 
    }

    @Test fun should_click_on_button_and_fail_login() {
        //init
        clickOn("#username").eraseText(10).write("anyuser")
        clickOn("#password").eraseText(10).write("anypwd")
        clickOn("#orgId").eraseText(10).write("anyorg")

        // when:
        clickOn("#submitBut")

        // then:
        //verify fail 
    }
}

您可以随时在App()类中添加可以编辑的属性。

class MyMainApp: App() {
    override val primaryView: KClass<out View> = primaryViewMyApp

    companion object {
        var primaryViewMyApp: KClass<out View> = MyMainAppView::class
    }

    init {
        importStylesheet(<your stylesheet>)
    }

    override fun start(stage: Stage) {
        super.start(stage)
    }

    override fun stop() {
        super.stop()
    }
}

在测试中,您可以使用任何想要使用的视图。 到目前为止,我没有尝试为Fragment实现一些东西......

    override fun init() {
        FxToolkit.registerStage { Stage() }
    }

    override fun start(stage: Stage) {
        MyMainApp.primaryViewGoApp = <your view>::class
        MyMainApp().start(stage)
    }

    override fun stop() {
        FxToolkit.cleanupStages()
        MyMainApp().stop()
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM