vendredi 15 janvier 2016

Providing tests as part of a library

Suppose an interface like:

public interface Fooer {
  void foo();
  boolean isFooed();
}

This is part of a Java library that I'm writing. Users of this library are supposed to implement this interface and pass objects into my library.

I want to provide a way for users to test their implementation to hold the invariants my library code assumes.

Following the above example:

Fooer f = getUsersFooer();
f.foo();
// f.isFooed() MUST return true now

Is it possible, and if so, feasible or even acceptable to provide such tests as part of the library?

(I don't know whether these would be considered unit tests or integration tests ... they test the modifications made by a single method using getter methods or very primitive non-mutating methods)

Sure, I can write classes like

public class TestFooer {
  public static boolean test(Fooer f) {
    // ...
  }
}

but is there a "standard way", using the usual testing frameworks (JUnit, ...) ?

Aucun commentaire:

Enregistrer un commentaire