edvin / tornadofx

Lightweight JavaFX Framework for Kotlin
Apache License 2.0
3.68k stars 272 forks source link

Tests for Builders. #7

Closed hastebrot closed 8 years ago

hastebrot commented 8 years ago

To test the builder pattern functions we need to create Nodes, thus we need to start the JavaFX thread.

There are JfxRunner (used by mvvmFX), Automaton and TestFX to start the JavaFX thread.

I'd like to improve TestFX's hasChildren() matcher and test the functions in Builders.kt with it. A test could look like this:

@Test
fun `label()`() {
    // when:
    val parent = StackPane().apply { label("foo") }

    // then:
    assertThat(parent, hasChild("foo"))
}
thomasnield commented 8 years ago

Have you tried just creating an instance of JFXPanel? I always found that the easiest way to kick off the JavaFX thread.

hastebrot commented 8 years ago

Jemmy (another UI test framework for JavaFX) and FEST-Swing (one for Swing) both completely require fixture classes for each UI control.

TestFX doesn't require fixture classes for user-interactions, but needs to implement fixtures for matchers that verify the state of UI controls.

edvin commented 8 years ago

I really appreciate this initiative. I haven't really done much UI testing, but now's the time to get started :)

Let's go with TestFX! Will you set up the dependencies and create a PR?

hastebrot commented 8 years ago

Have you tried just creating an instance of JFXPanel?

@thomasnield This should also be possible. Instead of hasChild() we could use the Nodes methods directly. This would require less dependencies.

(I'm a bit biased, because I'm the maintainer of TestFX and like to improve the UI control matchers :smile_cat:)

hastebrot commented 8 years ago

Let's go with TestFX! Will you set up the dependencies and create a PR?

I will. But first gotta go to sleep (Europe/Berlin timezone here).

hastebrot commented 8 years ago

@thomasnield: Can I use JFXPanel multiple times?

thomasnield commented 8 years ago

I'm curious to take a look at TestFX since I am the maintainer of RxJavaFX. I've been left with some misbehaving JavaFX tests.

thomasnield commented 8 years ago

Try this? https://github.com/ReactiveX/RxJavaFX/blob/0.x/src/test/java/rx/schedulers/JavaFxSchedulerTest.java#L69

thomasnield commented 8 years ago

Yes you can.

hastebrot commented 8 years ago

With JFXPanel, this is genius. One problem is, that I really need to fetch the primary Stage. Seems with JFXPanel it is not that easy.

I'm curious to take a look at TestFX since I am the maintainer of RxJavaFX. I've been left with some misbehaving JavaFX tests.

I'm happy to help you with TestFX, but first I need to implement some tests for TornadoFX.

thomasnield commented 8 years ago

@hastebrot that's nice of you thank you. No rush, even if it takes weeks. This issue I filed has been driving me up the wall. https://github.com/ReactiveX/RxJavaFX/issues/22

hastebrot commented 8 years ago

I think this could also lead to very constructive criticism on how to test controls. I haven' t had much feedback in this area about TestFX's API, and am eager to receive some criticism.

thomasnield commented 8 years ago

I know little about JavaFX testing so I'm curious to see how this works. Look forward to it.

edvin commented 8 years ago

When I added the fix for the tab builder I thought "how nice it would be to have tests for the builders!".. hehe :) It would be super nice to get the structure for builder tests set up, even if we don't have tests for everything. Would you like push access to the project, btw @hastebrot ?

hastebrot commented 8 years ago

@edvin Sure, why not. :smiley:

edvin commented 8 years ago

Granted :)

hastebrot commented 8 years ago

Thanks.

edvin commented 8 years ago

@hastebrot Do you have time to integrate some more tests here? Once I get some examples, I'm sure I can start fleshing out more tests, but I find it a bit hard to get started. If you don't have the time, I understand completely. Please let me know :)

hastebrot commented 8 years ago

@edvin Yes, I want to write more tests for the builders. This or the next week, when I find time.

edvin commented 8 years ago

Thanks @hastebrot :))

edvin commented 8 years ago

I'll close this issue for now, feel free to reopen if you get some time in your schedule to look at it :)