Skip to content

Commit 7873e82

Browse files
Merge pull request #504 from JordanMartinez/writeMoreTests
Write more TestFX tests
2 parents bbbc1ef + 2522d79 commit 7873e82

16 files changed

Lines changed: 1821 additions & 460 deletions

.ci/before_install.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/usr/bin/env bash
2+
3+
# Taken from TestFX and modified slightly
4+
if [[ "${TRAVIS_OS_NAME}" == osx ]]; then
5+
brew update
6+
brew cask install java
7+
brew install gradle
8+
brew unlink python # fixes 'run_one_line' is not defined error in backtrace
9+
fi

.travis.yml

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,48 @@
11
language: java
2-
jdk:
3-
- oraclejdk8
42

5-
os:
6-
- linux
3+
sudo: false # Linux OS: run in container
4+
5+
matrix:
6+
include:
7+
- os: linux
8+
dist: precise
9+
jdk: oraclejdk8
10+
- os: linux
11+
dist: trusty
12+
jdk: oraclejdk8
13+
14+
# Headless Build: xvfb + TestFX does not work on Travis OSX environments (as of 2017-05-24)
15+
- os: osx
16+
osx_image: xcode8.2
17+
env: _JAVA_OPTIONS="-Djava.awt.headless=true -Dtestfx.robot=glass -Dtestfx.headless=true -Dprism.order=sw -Dprism.text=t2k -Dtestfx.setup.timeout=2500"
718

819
# enable Java 8u45+, see https://github.com/travis-ci/travis-ci/issues/4042
920
addons:
1021
apt:
1122
packages:
1223
- oracle-java8-installer
1324

14-
# run in container
15-
sudo: false
16-
17-
# use framebuffer for UI
1825
before_install:
19-
- export DISPLAY=:99.0
20-
- sh -e /etc/init.d/xvfb start
26+
- chmod +x .ci/before_install.sh
27+
- .ci/before_install.sh
28+
29+
# skip install
30+
install: true
31+
32+
before_script:
33+
# Linux OS: Use framebuffer for UI
34+
# See https://docs.travis-ci.com/user/gui-and-headless-browsers/#Using-xvfb-to-Run-Tests-That-Require-a-GUI
35+
- if [[ "${TRAVIS_OS_NAME}" == linux ]]; then export DISPLAY=:99.0; sh -e /etc/init.d/xvfb start; fi
36+
37+
script:
38+
- gradle assemble
39+
- gradle check --stacktrace
40+
41+
# See https://docs.travis-ci.com/user/languages/java/#Caching
42+
before_cache:
43+
- rm -f $HOME/.gradle/caches/modules-2/modules-2.lock
44+
- rm -fr $HOME/.gradle/caches/*/plugin-resolution/
45+
cache:
46+
directories:
47+
- $HOME/.gradle/caches/
48+
- $HOME/.gradle/wrapper/

richtextfx/build.gradle

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,40 @@
1+
buildscript {
2+
repositories {
3+
jcenter()
4+
}
5+
dependencies {
6+
classpath 'org.unbroken-dome.gradle-plugins:gradle-testsets-plugin:1.3.2'
7+
}
8+
}
9+
110
apply plugin: 'maven'
211
apply plugin: 'signing'
12+
apply plugin: 'org.unbroken-dome.test-sets'
313

414
group = 'org.fxmisc.richtext'
515

16+
testSets {
17+
integrationTest { dirName = 'integrationTest' }
18+
}
19+
20+
check.dependsOn integrationTest
21+
integrationTest.mustRunAfter test
22+
623
dependencies {
724
compile group: 'org.reactfx', name: 'reactfx', version: '2.0-M5'
825
compile (group: 'org.fxmisc.undo', name: 'undofx', version: '1.3.1')
926
compile (group: 'org.fxmisc.flowless', name: 'flowless', version: '0.5.2')
1027
compile group: 'org.fxmisc.wellbehaved', name: 'wellbehavedfx', version: '0.3'
28+
1129
testCompile group: 'junit', name: 'junit', version: '[4.0,5)'
1230

13-
testCompile "org.testfx:testfx-core:4.0.5-alpha"
14-
testCompile ("org.testfx:testfx-junit:4.0.5-alpha") {
31+
integrationTestCompile group: 'junit', name: 'junit', version: '[4.0,)'
32+
integrationTestCompile group: 'com.nitorcreations', name: 'junit-runners', version: '1.2'
33+
integrationTestCompile "org.testfx:testfx-core:4.0.6-alpha"
34+
integrationTestCompile ("org.testfx:testfx-junit:4.0.6-alpha") {
1535
exclude(group: "junit", module: "junit")
1636
}
17-
testCompile group: 'com.nitorcreations', name: 'junit-runners', version: '1.2'
37+
integrationTestCompile "org.testfx:openjfx-monocle:8u76-b04"
1838
}
1939

2040
javadoc {
@@ -37,6 +57,39 @@ javadoc {
3757
]
3858
}
3959

60+
// use test logging.
61+
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
62+
import org.gradle.api.tasks.testing.logging.TestLogEvent
63+
64+
test {
65+
testLogging {
66+
// Fancy formatting from http://stackoverflow.com/a/36130467/3634630
67+
// set options for log level LIFECYCLE
68+
events TestLogEvent.PASSED, TestLogEvent.SKIPPED,
69+
TestLogEvent.FAILED, TestLogEvent.STANDARD_OUT
70+
showExceptions true
71+
exceptionFormat TestExceptionFormat.FULL
72+
showCauses true
73+
showStackTraces true
74+
75+
// set options for log level DEBUG and INFO
76+
debug {
77+
events TestLogEvent.STARTED, TestLogEvent.PASSED,
78+
TestLogEvent.SKIPPED, TestLogEvent.FAILED,
79+
TestLogEvent.STANDARD_OUT, TestLogEvent.STANDARD_ERROR
80+
}
81+
info.events = debug.events
82+
afterSuite { desc, result ->
83+
if (!desc.parent) { // will match the outermost suite
84+
def output = "Results: ${result.resultType} (${result.testCount} tests, ${result.successfulTestCount} successes, ${result.failedTestCount} failures, ${result.skippedTestCount} skipped)"
85+
def startItem = '| ', endItem = ' |'
86+
def repeatLength = startItem.length() + output.length() + endItem.length()
87+
println('\n' + ('-' * repeatLength) + '\n' + startItem + output + endItem + '\n' + ('-' * repeatLength))
88+
}
89+
}
90+
}
91+
}
92+
4093
task javadocJar(type: Jar, dependsOn: javadoc) {
4194
classifier = 'javadoc'
4295
from 'build/docs/javadoc'
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
package org.fxmisc.richtext;
2+
3+
import javafx.geometry.Pos;
4+
import javafx.scene.Scene;
5+
import javafx.scene.control.ContextMenu;
6+
import javafx.scene.control.MenuItem;
7+
import javafx.scene.input.MouseButton;
8+
import javafx.stage.Stage;
9+
import org.testfx.api.FxRobotInterface;
10+
import org.testfx.framework.junit.ApplicationTest;
11+
import org.testfx.service.query.PointQuery;
12+
13+
import static org.junit.Assume.assumeTrue;
14+
15+
/**
16+
* TestFX tests should subclass this if it needs to run tests on a simple area. Any view-related API needs to be
17+
* wrapped in a {@link #interact(Runnable)} call, but model API does not need to be wrapped in it.
18+
*/
19+
public class InlineCssTextAreaAppTest extends ApplicationTest {
20+
21+
static {
22+
String osName = System.getProperty("os.name").toLowerCase();
23+
24+
isWindows = osName.startsWith("win");
25+
isMac = osName.startsWith("mac");
26+
isLinux = osName.startsWith("linux");
27+
}
28+
29+
public static final boolean isWindows;
30+
public static final boolean isMac;
31+
public static final boolean isLinux;
32+
33+
public Stage stage;
34+
public Scene scene;
35+
public InlineCssTextArea area;
36+
public ContextMenu menu;
37+
38+
@Override
39+
public void start(Stage stage) throws Exception {
40+
area = new InlineCssTextArea();
41+
scene = new Scene(area);
42+
this.stage = stage;
43+
44+
stage.setScene(scene);
45+
stage.setWidth(400);
46+
stage.setHeight(400);
47+
stage.show();
48+
49+
menu = new ContextMenu(new MenuItem("A menu item"));
50+
area.setContextMenu(menu);
51+
// offset needs to be 5+ to prevent test failures
52+
area.setContextMenuXOffset(30);
53+
area.setContextMenuYOffset(30);
54+
55+
// so tests don't need to do this themselves
56+
area.requestFocus();
57+
}
58+
59+
public final PointQuery firstLineOfArea() {
60+
return point(area).atPosition(Pos.TOP_LEFT).atOffset(5, 5);
61+
}
62+
63+
public final FxRobotInterface clickOnFirstLine(MouseButton... buttons) {
64+
return moveTo(firstLineOfArea()).clickOn(buttons);
65+
}
66+
67+
public final FxRobotInterface leftClickOnFirstLine() {
68+
return clickOnFirstLine(MouseButton.PRIMARY);
69+
}
70+
71+
public final FxRobotInterface doubleClickOnFirstLine() {
72+
return leftClickOnFirstLine().clickOn(MouseButton.PRIMARY);
73+
}
74+
75+
public final FxRobotInterface tripleClickOnFirstLine() {
76+
return doubleClickOnFirstLine().clickOn(MouseButton.PRIMARY);
77+
}
78+
79+
public final FxRobotInterface rightClickOnFirstLine() {
80+
return clickOnFirstLine(MouseButton.SECONDARY);
81+
}
82+
83+
/**
84+
* If not on Windows environment, calling this in @Before method will skip the entire test suite whereas calling
85+
* this in @Test will skip just that test method
86+
*/
87+
public final void run_only_on_windows() {
88+
assumeTrue(isWindows);
89+
}
90+
91+
/**
92+
* If not on Linux environment, calling this in @Before method will skip the entire test suite whereas calling
93+
* this in @Test will skip just that test method
94+
*/
95+
public final void run_only_on_linux() {
96+
assumeTrue(isLinux);
97+
}
98+
99+
/**
100+
* If not on Mac environment, calling this in @Before method will skip the entire test suite whereas calling
101+
* this in @Test will skip just that test method
102+
*/
103+
public final void run_only_on_mac() {
104+
assumeTrue(isMac);
105+
}
106+
107+
/**
108+
* If on Windows environment, calling this in @Before method will skip the entire test suite whereas calling
109+
* this in @Test will skip just that test method
110+
*/
111+
public final void skip_if_on_windows() {
112+
assumeTrue(!isWindows);
113+
}
114+
115+
/**
116+
* If on Linux environment, calling this in @Before method will skip the entire test suite whereas calling
117+
* this in @Test will skip just that test method
118+
*/
119+
public final void skip_if_on_linux() {
120+
assumeTrue(!isLinux);
121+
}
122+
123+
/**
124+
* If on Mac environment, calling this in @Before method will skip the entire test suite whereas calling
125+
* this in @Test will skip just that test method
126+
*/
127+
public final void skip_if_on_mac() {
128+
assumeTrue(!isMac);
129+
}
130+
}

0 commit comments

Comments
 (0)