TestFX Spock Gradle Project Openjdk 11 - Нулевые результаты испытаний - PullRequest
0 голосов
/ 29 апреля 2019

Почему мой тест Спока не выполнен, и я получаю нулевые результаты теста при выполнении:

./gradlew clean test

с моим проектом TestFX Spock Gradle с Openjdk 11 ?


Вот результаты теста на ноль: enter image description here


Мой тестовый класс Спока в порядке, но не выполнен.

Вот моя консоль :

Working Directory: /home/~/EclipseProjects/gradleTestfxSpock
Gradle user home: /home/~/.gradle
Gradle Distribution: Gradle wrapper from target build
Gradle Version: 5.0
Java Home: /usr/lib/jvm/jdk-11.0.2+9
JVM Arguments: None
Program Arguments: None
Build Scans Enabled: false
Offline Mode Enabled: false
Gradle Tasks: clean test


> Configure project :
Found module name 'mtd'

> Task :clean
> Task :compileJava
> Task :compileGroovy NO-SOURCE
> Task :processResources
> Task :classes
> Task :compileTestJava NO-SOURCE
> Task :compileTestGroovy
> Task :processTestResources
> Task :testClasses
> Task :test

BUILD SUCCESSFUL in 6s
6 actionable tasks: 6 executed

Вот мой build.gradle :

plugins {    
    id 'org.openjfx.javafxplugin' version '0.0.7'   
    id 'application'
    id 'groovy'
}

mainClassName = 'mtd/gradleTestfxSpock.Main'

sourceCompatibility = 11
targetCompatibility = 11

repositories {  
    jcenter()   
}

dependencies {
    implementation 'org.testfx:testfx-spock:4.0.15-alpha'
    testCompile    'org.testfx:testfx-core:4.0.15-alpha'        

    testCompile (group: 'org.spockframework', name: 'spock-core', version: '1.3-groovy-2.5')
    testCompile ('org.codehaus.groovy:groovy-all:2.5.6')
    testRuntime(
        'com.athaydes:spock-reports:1.2.7',
        'cglib:cglib-nodep:3.2.4'
    )
}

javafx {
    version = "11.0.2"
    modules = [ 'javafx.controls',
            'javafx.fxml',
            'javafx.web'
          ]
}

compileJava {
    doFirst {
        options.compilerArgs = [
                '--module-path', classpath.asPath,
                '--add-modules', 'javafx.controls',
                '--add-modules', 'javafx.fxml',
                '--add-modules', 'javafx.web'
        ]
    }
}

test {
    doFirst {
        jvmArgs = [
            '--module-path', classpath.asPath,
            '--add-modules', 'ALL-MODULE-PATH',
            '--add-exports', 'javafx.graphics/com.sun.javafx.application=org.testfx'            
        ]
    }
}

Вот мой module-info.java :

module mtd {

requires javafx.controls;
requires javafx.fxml;
requires transitive javafx.graphics;
requires javafx.web;

requires org.testfx;
requires testfx.spock;  

opens gradleTestfxSpock to javafx.graphics;

exports gradleTestfxSpock;      
}

Вот мой тестовый код Спока :

package gradleTestfxSpock;

import org.testfx.framework.spock.ApplicationSpec;
import javafx.stage.Stage


public class MainTest extends ApplicationSpec{


    def "Main Test 01"() {              
        expect:     
        println("you are in Main test 01");     
    }

    @Override
    public void start(Stage arg0) throws Exception {
        // TODO Auto-generated method stub      
    }


}

Вот мой код JavaFX :

package gradleTestfxSpock;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;

public class Main extends Application {

    @Override
    public void start(Stage primaryStage) throws Exception{        
        Parent root = FXMLLoader.load(getClass().getResource("/fxml/sample.fxml"));        
        primaryStage.setTitle("Hello World");
    primaryStage.setScene(new Scene(root, 300, 275));
    primaryStage.show();
    }


    public static void main(String[] args) {
    launch(args);
    }
}

и контроллер :

package gradleTestfxSpock;
public class Controller {
}

Вот моя структура проекта Gradle Eclipse :

enter image description here


В других проектах затмения я успешно выполнил TestFX Junit4 тест без Спока :

enter image description here


и отдельно я успешно выполнил тот же тест Спока без TestFX и без JUnit :

enter image description here


Я заметил некоторые предупреждения в этом тесте Спока:

Working Directory: /home/~/EclipseProjects/gradleSpock
Gradle user home: /home/~/.gradle
Gradle Distribution: Gradle wrapper from target build
Gradle Version: 5.0
Java Home: /usr/lib/jvm/jdk-11.0.2+9
JVM Arguments: None
Program Arguments: None
Build Scans Enabled: false
Offline Mode Enabled: false
Gradle Tasks: clean test

> Task :clean
> Task :compileJava
> Task :compileGroovy NO-SOURCE
> Task :processResources NO-SOURCE
> Task :classes
> Task :compileTestJava NO-SOURCE
> Task :compileTestGroovy
> Task :processTestResources NO-SOURCE
> Task :testClasses

> Task :test
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.codehaus.groovy.vmplugin.v7.Java7$1 (file:/home/dm/.gradle/caches/modules-2/files-2.1/org.codehaus.groovy/groovy/2.5.6/6936e700f0fb1b50bac0698ada4347a769d40199/groovy-2.5.6.jar) to constructor java.lang.invoke.MethodHandles$Lookup(java.lang.Class,int)
WARNING: Please consider reporting this to the maintainers of org.codehaus.groovy.vmplugin.v7.Java7$1
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release

BUILD SUCCESSFUL in 9s
4 actionable tasks: 4 executed

Заключение

Если TestFX с JUnit работает и работает только Spock, но TestFX с Spock не работает, значит, что-то не так с настройкой:

'org.testfx:testfx-spock:4.0.15-alpha'

Любые идеи или помощь приветствуется.

ps Забыл сказать, что я также создал проект TestFX / Spock в Netbeans, дублирующий проект eclipse, и я получил тот же результат!


Дополнительные тесты

Больше комбинаций тестирования после Леонард Брюнингс, очень хорошие предложения в комментариях ниже, к сожалению, не сработало.

Мой измененный модуль-info.java выглядит так:

module mtd {

requires javafx.controls;
requires javafx.fxml;
requires transitive javafx.graphics;
requires javafx.web;

requires org.testfx.junit;
requires org.testfx;
requires testfx.spock;
requires spock.core;
requires junit;

opens gradleTestfxSpock to javafx.graphics, org.testfx, testfx.spock, spock.core, junit, org.testfx.junit;

exports gradleTestfxSpock;      
}

И я добавил это в мои зависимости gradle.build на всякий случай:

implementation 'org.testfx:testfx-junit:4.0.15-alpha'

Все еще нет радости ...

1 Ответ

0 голосов
/ 07 мая 2019

Решение

Я обнаружил, что этот плагин был проблемой, и остановил успешное выполнение моего теста Спока:

`plugins {    
    id 'org.openjfx.javafxplugin' version '0.0.7'
 }`

Когда я удалил его из своей сборки.gradle мой TestFX тест Спока работал нормально.

С этим переработанным build.gradle и module-info.java я могу успешно выполнить свой тест Спока:

plugins { 
    id 'application'
    id 'groovy'
}

ext {
    moduleName = "mtd"
    mainQualifiedClassName = "gradleTestfxSpock.Main"
}

application {
    mainClassName = "$moduleName/$mainQualifiedClassName"
}

sourceCompatibility = 11
targetCompatibility = 11

repositories {  
    jcenter()   
}

dependencies {
    implementation("org.openjfx:javafx-fxml:11:linux")
    implementation("org.openjfx:javafx-web:11:linux")
    implementation("org.openjfx:javafx-media:11:linux")
    implementation("org.openjfx:javafx-base:11:linux")
    implementation("org.openjfx:javafx-graphics:11:linux")
    implementation("org.openjfx:javafx-controls:11:linux")

    testImplementation ('org.testfx:testfx-spock:4.0.15-alpha')
    testImplementation ('org.testfx:testfx-core:4.0.15-alpha')

    testImplementation (group: 'org.spockframework', name: 'spock-core', version: '1.3-groovy-2.5')
    testImplementation ('org.codehaus.groovy:groovy-all:2.5.6')

    testRuntimeOnly (
            'com.athaydes:spock-reports:1.2.7',
            'cglib:cglib-nodep:3.2.4'
    )
}


compileJava {
    doFirst {
       options.compilerArgs = [
            '--module-path', classpath.asPath,
            '--add-modules', 'javafx.controls',
            '--add-modules', 'javafx.fxml',
            '--add-modules', 'javafx.web'
       ]
    }
}

run {
    doFirst {
        jvmArgs = [
                '--module-path', classpath.asPath,
                '--patch-module', "$moduleName=" + files(sourceSets.main.output.resourcesDir).asPath,
                '--module', mainClassName
        ]   
    }
}

Мне нужно было добавить в секцию запуска build.gradle:

  1. '--module', mainClassName

    , чтобы можно было найти mainClassName

  2. '--patch-module', "$moduleName=" + files(sourceSets.main.output.resourcesDir).asPath

    -для доступа к файлам ресурсов, например getClass().getResource("/fxml/sample.fxml")


module mtd {

requires javafx.controls;
requires javafx.fxml;
requires transitive javafx.graphics;
requires javafx.web;


exports gradleTestfxSpock;
}
...