FarmIntegrationTest with Gradle and TestNG fails to run?

372 Views Asked by At

I am trying to use the gretty farmIntegrationTest to call a test suite setup with TestNG. But the tests don't run.

The farm starts up, then exits cleanly with no indication that the tests were even attempted.

Here are the Gradle fragments for review:

Gretty config:

gretty {
    integrationTestTask = 'firefoxTest'
    httpPort = 8080;
    servletContainer = 'tomcat8'
    extraResourceBase 'build/gwt/out'
    jvmArgs = ['-Dfile.encoding=UTF-8', '-Xmx6144M']
}

Test task config:

task firefoxTest(type: Test)  {
  useTestNG()
  maxHeapSize = "512m"
}

Here is my starting test class:

package selenium.test;

import java.io.File;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Test;

public class Farm {
    private WebDriver driver=null;
    @BeforeSuite
    public void init() {
        System.setProperty("webdriver.gecko.driver", new File("drivers/linux-x64/geckodriver").getAbsolutePath());
        driver = new FirefoxDriver();
    }
    @AfterSuite
    public void teardown() {
        if (driver!=null) {
            driver.close();
        }
    }
    @Test
    public void isFarmAlive() throws InterruptedException {
            driver.navigate().to("http://localhost:8080/RestyGwtCodecTester/");
            Thread.sleep(10000);
    }
}

Output:

michael@michael-desktop:~/git/RestyGwtCodecTester/RestyGwtCodecTester$ gradle farmintegrationtest
Parallel execution is an incubating feature.

> Configure project :
Gradle now uses separate output directories for each JVM language, but this build assumes a single directory for all classes from a source set. This behaviour has been deprecated and is scheduled to be removed in Gradle 5.0
        at build_9lyawgow85f0zt9zngx2sy6wt$_run_closure3.doCall(/home/michael/git/RestyGwtCodecTester/RestyGwtCodecTester/build.gradle:51)
        (Run with --stacktrace to get the full stack trace of this deprecation warning.)

Oct 10, 2017 10:48:13 AM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-nio-8080"]
Oct 10, 2017 10:48:13 AM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
INFO: Using a shared selector for servlet write/read
Oct 10, 2017 10:48:13 AM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Tomcat
Oct 10, 2017 10:48:13 AM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/8.0.44
Oct 10, 2017 10:48:13 AM org.apache.catalina.startup.ContextConfig getDefaultWebXmlFragment
INFO: No global web.xml found
Oct 10, 2017 10:48:14 AM org.apache.jasper.servlet.TldScanner scanJars
INFO: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
Oct 10, 2017 10:48:14 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-nio-8080"]
10:48:14 INFO  Tomcat 8.0.44 started and listening on port 8080
10:48:14 INFO  RestyGwtCodecTester runs at:
10:48:14 INFO    http://localhost:8080/RestyGwtCodecTester
Oct 10, 2017 10:48:14 AM org.apache.coyote.AbstractProtocol pause
INFO: Pausing ProtocolHandler ["http-nio-8080"]
Oct 10, 2017 10:48:14 AM org.apache.catalina.core.StandardService stopInternal
INFO: Stopping service Tomcat
Oct 10, 2017 10:48:14 AM org.apache.coyote.AbstractProtocol stop
INFO: Stopping ProtocolHandler ["http-nio-8080"]
Oct 10, 2017 10:48:14 AM org.apache.coyote.AbstractProtocol destroy
INFO: Destroying ProtocolHandler ["http-nio-8080"]

> Task :farmAfterIntegrationTest
Server stopped.


BUILD SUCCESSFUL in 4s
12 actionable tasks: 2 executed, 10 up-to-date
michael@michael-desktop:~/git/RestyGwtCodecTester/RestyGwtCodecTester$ 
2

There are 2 best solutions below

0
On

Ok, so it appears that the test task is "extended" when I specify the farmintegrationtest value and the correct command is:

gradle firefoxTest

and not

gradle farmIntegrationTest

this was not obvious from the documentation for gretty to me.

It also skips the test if the tests are marked as "up-to-date" though the farm starts and stops anyways adding to my confusion.

I have adjusted my config for the test task to read:

task firefoxTest(type: Test)  {
  useTestNG()
  dependsOn 'cleanTest'
  maxHeapSize = "512m"
}

so that the test suite will run each time it is called without regard to previous success or failure.

0
On

gradle integrationTest should run your test task(firefoxTest) not gradle farmIntegrationTest