Giter Club home page Giter Club logo

demo-junit-karma-testrunner's Introduction

AngularJS Phone Catalog Tutorial Application as Java-Maven-App

Overview

This is a simple web app based on the angular tutorial to show how to use the KarmaTestSuiteRunner. This app was created with maven "archetypeArtifactId=maven-archetype-webapp" and should represent a common java based web application. The angular tutorial app "angular-phonecat" was copied and the test execution is done by the KarmaTestSuiteRunner in a JUnit way as described below.

Motivation: Why using another JUnit test runner instead of karma itself?

A JUnit test runner is fully integrated in any modern JAVA supporting IDE. In most cases a right-click on a test folder and you can execute all java tests with JUnit. With a JUnit runner you see the execution in realtime in form of some nice green or red bubbles - now you will see something like that for your javascript tests too which is nice when you have long running e2e (integration) tests. One tool (JUnit) to rule them all ;)

In addition you can use the JUnit @BeforeClass/@AfterClass method to setup and cleanup your test scenarios for e2e tests.

And last but not least the JUnit test runner can be used to integrate karma in other frameworks like Grails so that the grails command "test-app" will execute your javascript test with the powerful karma framework too. (The grails plugin will follow soon - visit ImmobilienScout24 at github for mor informations).

Usage

Before you can start clone this web app...

You should have some experience with karma - the angular tutorial (http://docs.angularjs.org/tutorial) should be good start...

  • YOU NEED JAVA >= 1.7 TO RUN THIS APP

Running the webapp

Use the embedded jetty via maven:

mvn jetty:run
mvn jetty:stop

Browse to http://localhost:8080 to see the angular-phonecat webapp in action...

Running the tests

To run the test you need to install:

  • nodejs (http://nodejs.org/)
  • you'll need a chrome or change the karma config which is under test/resources/config (see karma documention)

The webapp ships already with a package.json which install all required dependencies. Go into the root folder of the webapp and execute the following command in a console:

npm install

This will install karma and the required karma plugins into the /node_modules folder.


To run the javascript unit test without JUnit and pure karma style, execute the following command from the webapp root dir:

./scripts/test_original.sh

If you have a window system run the batch file instead of the shell script...

Ah - you'll hopefully see the successful execution of some javascript tests in chrome. If you not already have found the tests itself have a look at test/javascript/unit/...


To run the javascript e2e test without JUnit and pure karma style, execute the following command from the webapp root dir:

mvn jetty:run
./scripts/e2e-test_original.sh
mvn jetty:stop

If you have a window system run the batch file instead of the shell script...

Ah - you'll hopefully see the successful execution of some javascript tests in chrome. If you not already have found the tests itself have a look at test/javascript/e2e/...


To run the javascript unit test with JUnit, run the JavaScriptUnitTest (test/java/...) class as a normal JUnit test.

To run the javascript e2e test with JUnit, you have to start the jetty first (s.o.) Run the JavaScriptIT class (test/java/...) class as a normal JUnit test. Do not forget to stop the jetty...


To run the javascript unit test with JUnit and maven:

mvn test

To run the javascript e2e test with JUnit and maven (make sure that no jetty is already running):

mvn integration-test

To run all tests with JUnit and maven (make sure that no jetty is already running):

mvn verify

Use the KarmaTestSuiteRunner in your own project

The KarmaTestSuiteRunner is still a snapshot version. Make sure your pom allows snapshots:

<repositories>
    <repository>
        ...
        <snapshots>
            <enabled>true</enabled>
            <updatePolicy>always</updatePolicy>
            <checksumPolicy>fail</checksumPolicy>
        </snapshots>
        ...
    </repository>
</repositories>

These are the needed dependencies:

<dependency>
    <groupId>de.is24.util</groupId>
    <artifactId>junit-karma-testrunner</artifactId>
    <version>1.0-SNAPSHOT</version>
    <type>jar</type>
</dependency>

Issues

The KarmaTestSuiteRunner is still a snapshot version, so every bug report or change requests are welcome. Use the github issue page for this webapp or even better: https://github.com/ImmobilienScout24/junit-karma-testrunner

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.