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

Build vs Buy a Data Quality Solution: Which is Best for You? Gain insights on a hybrid approach. Download white paper now!

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 vs Buy a Data Quality Solution: Which is Best for You? Maintaining high quality data is essential for operational efficiency, meaningful analytics and good long-term customer relationships. But, when dealing with multiple sources of data, data quality becomes complex, so you need to know when you should build a custom data quality tools effort over canned solutions. Download our whitepaper for more insights into a hybrid approach.

Topics:

Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}