Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Integrating SureAssert with Existing Projects

DZone's Guide to

Integrating SureAssert with Existing Projects

· Java Zone
Free Resource

Learn how to troubleshoot and diagnose some of the most common performance issues in Java today. Brought to you in partnership with AppDynamics.

I recently blogged about SureAssert’s ability to do automatic, continuous, declaration driven testing using annotations, which could make JUnit test classes obsolete. When picking up any new and useful development tool, the first question asked is usually “how can it help my existing project?” The answer here is that SureAssert integrates with existing JUnit test code, which gives you the benefit of having your existing JUnit tests continuously monitored and executed.

To integrate SureAssert with an existing project, you’ll need to add the SureAssert Annotation jar file, which is currently: org.sureassert.uc.annotation-1.1.0.jar, to your project. This JAR file isn’t currently available from Maven Central, so you’ll need to add it manually to your local repository using the maven install file command. You’ll need to execute something like:

mvn install:install-file -DgroupId=sureassert -DartifactId=annotations -Dversion=1.1.0 -Dpackaging=jar -Dfile={path to}/org.sureassert.uc.annotation-1.1.0.jar

Having made this JAR file available to your application, the next step is to annotate the classes that you want SureAssert to monitor. Going back to the Calculator example used in my last blog, then for SureAssert to pick-up Calculator's JUnit test class, CalculatorTest, you'll need to add the following annotation to your Calculator class:

@HasJUnit(jUnitClassNames = "com.sureassert.uc.tutorial.mytests.CalculatorTest")
public final class Calculator {

  @UseCase(args = { "1", "2" }, expect = "3")
  public int add(int x, int y) {

    return x + y;
  }

  @UseCase(name = "multiplyTest", args = { "4", "2" }, expect = "8")
  public int multiply(int x, int y) {

    return x * y /* + 1 */;
  }

  /**
   * This method is served by a JUnit test
   */
  public int subtract(int x, int y) {

    return x - y;
  }

}

Note that’ll you need the fully qualified class name of your JUnit test as an attribute to the HasJUnit annotation.

The SureAssert plugin with then automatically run the CalculatorTest JUnit when necessary and test failures will be shown as errors:


If your tests follow the FIRST acronym, and your tests are fast then attaching @HasJUnit is a good idea. I would suspect that badly written, slow and end to end tests may make eclipse run slowly. This this case, don’t blame SureAssert, take a look at your tests...

 

From http://www.captaindebug.com/2011/09/integrating-sureassert-with-existing.html

Understand the needs and benefits around implementing the right monitoring solution for a growing containerized market. Brought to you in partnership with AppDynamics.

Topics:

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}