On Mar 31, 2006, at 05:57, Tomasz Pik wrote:

On 3/31/06, Carlos Sanchez <[EMAIL PROTECTED]> wrote:

It means that test can be reused in other projects, so you can extend or use them from the tests in that project. What is the point of runing the same tests again in another project?

For example when you want to test some implementations of given API. And tests 'bootstraps' implementation using some properties. Something like TCK for JAXP implementation for example, with tests starting with - Djavax.xml.parsers.DocumentBuilderFactory=my.jaxp.impl.DBF (I've never seen a TCK for JAXP but I can imagine that such approach for testing implementations makes sense).

I can second the usefulness of this. Conformance tests in base classes are a very useful feature. I implemented these in a C# test harness at one point; the initial implementation was simply running all Test-annotated methods in non-abstract classes, regardless of whether the test methods were inherited or declared there. When I moved the unit tests to separate test assemblies, the pattern changed: Instead, a base class would come with an abstract test case:

/* base.dll */
abstract public class Base {
    abstract public object Memento { get; set; }
    abstract public bool SharesMemento(Base b);
}

/* base_t.dll */
abstract public class BaseTest {
    abstract protected Base CreateBase();
    [Test] public void TestMemento() {
        Base one = CreateBase();
        Base two = CreateBase();
        two.Memento = one.Memento;
        AssertTrue(one.SharesMemento(two));
        AssertTrue(two.SharesMemento(one));
    }
}

And the subclass would also author a derived test case:

/* sub.dll */
abstract public class Sub : Base {
    static counter = 0;
    int token = counter++;
    override public object Memento {
        get { return (object) token; }
        set { i = (int) token; }
    }
    override public bool SharesMemento(Base b) {
        return b is Sub && ((Sub) b).token == this.token;
    }
}

/* sub_t.dll */
abstract public class SubTest : BaseTest {
    abstract protected Base CreateBase() { return new Sub(); }
}

Might a similar pattern work with surefire?

    base/
       src/test/java/com/example/Base.java
    base-conformance-suite/ { depends: main }
       src/test/java/com/example/BaseConformanceTest.java
    sub/ { depends: base, base-conformance { scope: test } }
       src/main/java/com/example/Sub.java { extends: Base }
src/test/java/com/example/SubTest.java { extends: BaseConformanceTest }

I'm not sure if surefire will find the inherited test methods, though.

Very excited about the TestNG support in surefire 2, BTW. Also, war merging will find use very swiftly indeed.

— G


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to