Loading ...
Sorry, an error occurred while loading the content.

junit test for interfaces

Expand Messages
  • Stefan Lischke
    hi there, I have a well defined API and a bunch of different implementations of this API. I want to make some jUnit Tests for the API using the interfaces, so
    Message 1 of 7 , Dec 1, 2003
    View Source
    • 0 Attachment
      hi there,

      I have a well defined API and a bunch of different implementations of
      this API. I want to make some jUnit Tests for the API using the
      interfaces, so that all implementations could be verified against this
      API Junit Test.

      What is the standard way to do this?
      How can i minimize the adaption work for every different implementation.
      Is there a way of just testing against the interfaces and maybe just
      derrivate one Main class for every implementation.

      thanx in advance
    • J. B. Rainsberger
      ... http://c2.com/cgi/wiki?AbstractTestCases -- J. B. Rainsberger, Diaspar Software Services http://www.diasparsoftware.com :: +1 416 791-8603 Let s write
      Message 2 of 7 , Dec 1, 2003
      View Source
      • 0 Attachment
        Stefan Lischke wrote:

        > hi there,
        >
        > I have a well defined API and a bunch of different implementations of
        > this API. I want to make some jUnit Tests for the API using the
        > interfaces, so that all implementations could be verified against this
        > API Junit Test.
        >
        > What is the standard way to do this?

        http://c2.com/cgi/wiki?AbstractTestCases
        --
        J. B. Rainsberger,
        Diaspar Software Services
        http://www.diasparsoftware.com :: +1 416 791-8603
        Let's write software that people understand
      • Michael Hill
        Stefan... Monday, December 1, 2003, 7:38:51 AM, you wrote: SL What is the standard way to do this? Here s how I generally handle it. It defies the usual
        Message 3 of 7 , Dec 2, 2003
        View Source
        • 0 Attachment
          Stefan...

          Monday, December 1, 2003, 7:38:51 AM, you wrote:

          SL> What is the standard way to do this?

          Here's how I generally handle it. It defies the usual JUnit advice of
          doing no work in the constructor, but I am basically ill-behaved, and
          this is no exception. :)

          Hill

          class ABCTestBase extends TestCase
          {
          public ABCTestBase(String Name, ABCInstance instance)
          {
          super(name);
          this.instance = instance;
          }

          pubic void testSomething()
          {
          instance.this and that();
          assertThisAndThat()
          }
          }

          class MikeTest extends ABCTestBase
          {
          public MikeTest(String name)
          {
          super(name,new Mike());
          }
          }


          +------------------------------------+
          | Mike Hill <uly@...> |
          | Michael Hill Associates |
          | Software |
          | Satisfaction Guaranteed |
          +------------------------------------+
        • J. B. Rainsberger
          ... He uses Parameterized Test Case! Huzzah! I have been asking the question, does the Parameterized Test Case pattern eliminate the need for the Abstract Test
          Message 4 of 7 , Dec 2, 2003
          View Source
          • 0 Attachment
            Michael Hill wrote:

            > Stefan...
            >
            > Monday, December 1, 2003, 7:38:51 AM, you wrote:
            >
            > SL> What is the standard way to do this?
            >
            > Here's how I generally handle it. It defies the usual JUnit advice of
            > doing no work in the constructor, but I am basically ill-behaved, and
            > this is no exception. :)

            He uses Parameterized Test Case! Huzzah!

            I have been asking the question, does the Parameterized Test Case
            pattern eliminate the need for the Abstract Test Case pattern? Here's
            one person who uses the former over the latter.
            --
            J. B. Rainsberger,
            Diaspar Software Services
            http://www.diasparsoftware.com :: +1 416 791-8603
            Let's write software that people understand
          • Michael Hill
            J.B. .... Tuesday, December 2, 2003, 11:22:40 AM, you wrote: JBR I have been asking the question, does the Parameterized Test Case JBR pattern eliminate the
            Message 5 of 7 , Dec 2, 2003
            View Source
            • 0 Attachment
              J.B. ....

              Tuesday, December 2, 2003, 11:22:40 AM, you wrote:

              JBR> I have been asking the question, does the Parameterized Test Case
              JBR> pattern eliminate the need for the Abstract Test Case pattern? Here's
              JBR> one person who uses the former over the latter.

              Whichever pattern one prefers, the more important point is probably
              that they both get developers to extend TestCase. On a more or less
              daily basis I come across unbelievably poorly factored TestCase code,
              even from folks whose shipping code is pristine. One's first
              derivation off of TestCase is really all it takes to realize that you
              can kill tons and tons of dup just by hierarchizing the cases.

              A further step in this direction is building testing helpers of
              various sorts to share code amongst cases. My most common use for this
              is all the file-oriented crap. I don't normally factor my shipping
              code so that it opens/closes/deletes files, but such factoring is
              super-common in retrofit situations. Even in the event that only one
              or two objects do all the work of turning files into streams, one
              still has to test those two objects before turning them loose. When
              you're AT'ing, this kind of work is even more common.

              Hill


              +------------------------------------+
              | Mike Hill <uly@...> |
              | Michael Hill Associates |
              | Software |
              | Satisfaction Guaranteed |
              +------------------------------------+
            Your message has been successfully submitted and would be delivered to recipients shortly.