Skip to content
reusable tests library
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.settings updated eclipse settings to new version Feb 27, 2018
main added junit anchor in documentation Aug 31, 2018
run
test clarified error message in assert exception and added missing tests Aug 31, 2018
.classpath
.gitignore extracted SINK constant in scripts Mar 29, 2015
.project renamed project testanza->quackery Mar 14, 2015
README.md

README.md

Having comprehensive collection of tests is something every TDD practitioner aims for. But often writing tests gets tedious and we cut corners due to practical reasons.

  • Do you test all getters and setters of every bean?
  • Do you test equals and hashCode of every value object you write?
  • Do you test every corner case when implementing List or Set?

Quackery lets you write those tests once and reuse them in different contexts.

Reusable test can be something simple, like trivial assertion.

import static java.lang.String.format;
import static java.util.Arrays.asList;
import static org.quackery.Case.newCase;
import static org.quackery.Suite.suite;
import static org.quackery.report.AssertException.assertTrue;

import org.junit.runner.RunWith;
import org.quackery.Quackery;
import org.quackery.Test;
import org.quackery.junit.QuackeryRunner;

@RunWith(QuackeryRunner.class)
public class StringTest {
  @Quackery
  public static Test string_is_equal_to_itself() {
    return suite("string is equal to itself")
        .add(isEqualToItself("one"))
        .add(isEqualToItself("two"))
        .add("three", StringTest::isEqualToItself)
        .addAll(asList("four", "five", "six"), StringTest::isEqualToItself);
  }

  private static Test isEqualToItself(Object value) {
    return newCase(
        format("%s is equal to itself", value),
        () -> assertTrue(value.equals(value)));
  }
}

StringTest.png

But it can be something big, like a customizable contract for testing whole class. For example, quackery has built-in contract for testing that given Class implements Collection contract.

@RunWith(QuackeryRunner.class)
public class ArrayListTest {
  @Quackery
  public static Test test() {
    return quacksLike(Collection.class)
        .implementing(List.class)
        .test(ArrayList.class);
  }
}

ArrayListTest.png

See documentation for all features.

You can’t perform that action at this time.