Giter Site home page Giter Site logo

qunit-test-driver's Introduction

To get started, add QunitTestDriver to your existing Maven project. Next, create a JUnit test that extends QUnitTest, implementing the required methods:

public class ExampleQUnitTest {
    @Test
    public String getTestPageUrl() {
        return QUnitTestDriver.run("path/to/qUnitTest.html");
    }
}

QUnitTestDriver supports some additional configuration options that you can supply right inside of your Java test - No need to edit external configuration files such as XML or build scripts. Configuration is managed through the optional Varargs of Configuration objects like this:

public class ExampleQUnitTest {
    @Test
    public String getTestPageUrl() {
        return QUnitTestDriver.run("path/to/qUnitTest.html", new Configuration(configurationOptions)...);
    }
}

Pausing The Test Just After The Server Starts

Javascript treats HTML loaded from a "file://" URL different from HTML loaded from an "HTTP://" URL. For this reason, QUnitTestDriver starts a lightweight Jetty server for each test. It's common, especially when first starting, to have trouble where exactly the test is relative to where Jetty started. This configuration option will cause the test to join to the Jetty server which prevents the test from completing on its own.

@Test public void testQunitPage(){
    QUnitTestDriver.run("path/to/qUnitTest.html", new JoinToServer());
}

Changing The Port The Server Runs On

QUnitTestDriver is configured to try a fixed set of ports by default. Each time the internal server starts, a set of ports is consulted in order until the server is able to start. This is good if you use a CI system such as Jenkins that could run several tests in parallel on the same machine. You can configure the port or ports that are tried by passing in a new set.

@Test public void testQunitPage(){
    QUnitTestDriver.run("path/to/qUnitTest.html", new PortSet(8080, 8081, 8082));
}

Changing The Server Root

Let's say you would like the server to host files from multiple directories...

@Test public void testQunitPage(){
    QUnitTestDriver.run(
        "path/to/qUnitTest.html",             
        new PathMapping("/", "/some/path/on/the/file/system"),
        new PathMapping("/tests", "/another/path/on/the/file/system"),
        new PathMapping("/css", "/some/other/path/on/the/file/system"),
        new PathMapping("/html", "/last/one/i/swear/herp/derp")
    );
}

Emulating Different Browsers

QunitTestDriver? uses HTMLUnit under the covers which comes along with the ability to emulate different browsers. The default is Firefox 3.6, but you can choose a different browser like this:

@Test public void testQunitPage(){ 
    QUnitTestDriver.run("path/to/qUnitTest.html", new EmulateBrowser(BrowserVersion.INTERNET_EXPLORER_8)); 
}

Browsers available are listed in the HTMLUnit Documentation.

qunit-test-driver's People

Contributors

ratamacue avatar stupenrose avatar zeroem avatar markw avatar darkone23 avatar kirkfin avatar stevewitt99 avatar

Watchers

 avatar Hal Arnold avatar  avatar  avatar Franklin Henderson avatar  avatar  avatar Bill Adams avatar Aaron Cave avatar Ed Langley avatar Nicolás Font avatar James Cloos avatar Hitesh Lad avatar George Vamos avatar  avatar Anthony Coccia avatar Paul Roberts avatar  avatar Eugene Yusim avatar Josh King avatar John Emmer avatar Dan Chong avatar Karun avatar  avatar Serra Allgood avatar Liz Hurley avatar Zhuocheng Yu avatar  avatar  avatar Jeegar Shah avatar Robert Duffy avatar David Siefert avatar Greg Wiley avatar Sam avatar Mircea avatar  avatar Mary avatar  avatar Vivek Sachdeva avatar Michael Adlai Arnold avatar jasmine samra avatar Cezar avatar Jeff To avatar  avatar JC Balcita avatar Fannzy avatar  avatar  avatar Jeremy Simpson avatar Mark B avatar Roscoe Huo avatar

qunit-test-driver's Issues

JUnit calculates time for test taken incorrectly

When running a QUnitTest (e.g. through maven at the CLI), the actual time take to run the test is not reported correctly. Example:

Running cj.prc.arc.JavaScriptQUnitTest
Tests run: 352, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.067 sec

This particular unit test takes closer to 30 seconds, but the output shows it as taking only 0.067 seconds. Ideally, we would be able to see how long each individual test case takes as well.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.