Giter Club home page Giter Club logo

junit-remote's Introduction

Run JUnit tests remotely

This is a JUnit extension which allows you to run any JUnit test remotely.

It supports any existing runner, and will fall back to running tests locally if the remote test server is not running.

Why would you want to do this?

  • If you're using JRebel you are probably used to being able to get code changes into your running server fast. But what about running tests? Starting up a remote JUnit server with JRebel enabled, you'll get all the benefits of using JRebel also when writing tests. Of course, this is mostly relevant when writing integration tests, for example in Spring, which need to boot up an application context to run the test.
  • If you have a big collection of tests, and you want to run them concurrently on a cloud-ish manner

Setting up:

  • Add the required jar files to your project
  • Add @RunWith(RemoteTestRunner.class) to your test classes. The annotation can be placed on a superclass.
  • Optionally @Remote to specify the location of the remote server as well as the test runner to use.
  • Start the remote server. This can be done from an Ant script.

This script assumes that the init target sets up the classpath properly:

<target name="runtest" depends="init">
	<java classname="com.tradeshift.test.remote.RemoteServer" classpathref="classpath" fork="true">
		<classpath>
			<path refid="classpath" />
			<pathelement location="${basedir}/target/test-classes" />
			<pathelement location="${basedir}/target/classes" />
		</classpath>
	</java>
	
</target>
  • Run any test from Maven, Eclipse or whatever you are used to.

Concurrent execution

The remote runner also supports concurrent execution. This is toggled automatically if the @Remote endpoint points to a comma-separated list of urls.

In that case, each url will be run concurrently. If you have zero state in your tests, you can set the same url more times to run concurrently against the same instance.

Complete example

To use with JRebel, simply add the JRebel agent as a . Here's a complete example:

<target name="runtest" depends="init">
	<property environment="env"/>
	
	<fail message="JREBEL_HOME must be set">
		<condition><not><resourceexists><file file="${env.JREBEL_HOME}/jrebel.jar" /></resourceexists></not></condition>
	</fail>
	
	<artifact:dependencies pathId="classpath" useScope="test">
		<pom file="${basedir}/pom.xml" />
	</artifact:dependencies>
    <artifact:mvn fork="true" pom="${basedir}/pom.xml">
        <arg value="test-compile" />
    </artifact:mvn>
	<echo file="target/test-classes/rebel.xml"><![CDATA[
		<?xml version="1.0" encoding="UTF-8"?>
		<application xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.zeroturnaround.com" xsi:schemaLocation="http://www.zeroturnaround.com http://www.zeroturnaround.com/alderaan/rebel-2_0.xsd">

		    <classpath fallback="default">
		        <dir name="${basedir}/target/test-classes">
		        </dir>
		        <dir name="${basedir}/target/classes">
		        </dir>
		    </classpath>

		    <web>
		        <link target="/">
		            <dir name="${basedir}/src/main/webapp">
		            </dir>
		        </link>
		    </web>

		</application>
]]>
	</echo>
	<java classname="com.tradeshift.test.remote.RemoteServer" classpathref="classpath" fork="true">
		<classpath>
			<path refid="classpath" />
			<pathelement location="${basedir}/target/test-classes" />
			<pathelement location="${basedir}/target/classes" />
		</classpath>
		<jvmarg value="-Dconfig.location=file:${configurationLocation}"/>
		<jvmarg value="-XX:MaxPermSize=512m" />
		<jvmarg value="-Xmx1024m" />
		<jvmarg value="-javaagent:${env.JREBEL_HOME}/jrebel.jar" />
	</java>
	
</target>
<target name="init">
	<mkdir dir="${basedir}/target" />
	<available file="${basedir}/lib/maven-ant-tasks-2.1.3.jar" property="tasks-exists" />
	<antcall target="-download" />

	<path id="maven-ant-tasks.classpath" path="${basedir}/lib/maven-ant-tasks-2.1.3.jar" />
	<typedef resource="org/apache/maven/artifact/ant/antlib.xml" uri="antlib:org.apache.maven.artifact.ant" classpathref="maven-ant-tasks.classpath" />
</target>

junit-remote's People

Contributors

recht avatar thomedw avatar

Stargazers

 avatar

Watchers

 avatar  avatar

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.