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

Try Okta to add social login, MFA, and OpenID Connect support to your Java app in minutes. Create a free developer account today and never build auth again.

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

Build and launch faster with Okta’s user management API. Register today for the free forever developer edition!

Topics:

Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}