From Resin 3.0

Jump to: navigation, search

Running Resin inside jUnit

[Verified with Resin 3.1.5 and jUnit-4.4]

The new Resin embedding features of Resin 3.1.5 simplify and speed-up unit testing. Since the embedded Resin can be tested without using an external HTTP/TCP connection, the setup and overhead is low.

The test will point to an expanded web-app directory, e.g. in the build area. It's also possible to expand from a .war file to a temp directory.

Suppose there's a single Quercus/PHP page, test.php we want to test, like:

$a = $_GET["a"];
$b = $_GET["b"];

echo "$a + $b = " . ($a + $b); ?>

The jUnit test class might look like:

package qa;

import org.junit.*;
import static org.junit.Assert.*;
import com.caucho.resin.*;

public class MyTest {
  private static ResinEmbed _resin;

  public static void setup()
    _resin = new ResinEmbed();
    WebAppEmbed webApp = new WebAppEmbed("/", "file:/tmp/caucho/qa/test");

  public void test1plus1()
    throws java.io.IOException
    assertEquals(_resin.request("GET /test.php?a=1&b=1"), "1 + 1 = 2");

  public void test1plus2()
    throws java.io.IOException
    assertEquals(_resin.request("GET /test.php?a=1&b=2"), "1 + 2 = 3");

  public static void shutdown()
    if (_resin != null)
Personal tools