Announcement Announcement Module
Collapse
No announcement yet.
Setting order of AbstractTransactionalSpringContextTests Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Setting order of AbstractTransactionalSpringContextTests

    JUnit's TestCase has a default (no-args) constructor, and a constructor which receives the name of the test.

    But AbstractTransactionalSpringContextTests doesn't have such constructors, so I can't define a suite method like this:
    Code:
        public static TestSuite suite()
        {
            TestSuite tests = new TestSuite();
            tests.addTest(new DocumentoDAOTest("testIncluirDocumento"));
            tests.addTest(new DocumentoDAOTest("testBuscaDocumentoPorTitulo"));
           return tests;
        }
    How can I specify the order of the tests with AbstractTransactionalSpringContextTests ?

  • #2
    What I learned, is that one should not rely on the order of one's TestCases, especially not when emulating and testing transactional behaviour.

    Solution: write TestCases that are independent of the execution order.

    Apart from that, I don't know the answer to your question ..

    Rgrds, T.

    Comment


    • #3
      Save, then find

      Thanks for the reply. How do you implement the "save, then find" pattern without relying on the tests' order?
      That is, one test saves an entity, and another test searches for the just-inserted entity?

      Comment


      • #4
        I think the answer to your question is in this post:

        http://forum.springframework.org/showthread.php?t=14647

        You should implement and use the flushChangesAndClearSession() method.

        I did not try this specific approach myself yet, but I think it is viable.

        What do others say?

        HTH. Thomas
        Last edited by robyn; May 14th, 2006, 11:50 AM.

        Comment


        • #5
          To reiterate: JUnit explicitly forbides you relying on the ordering of the tests!

          ATM the tests are run sequentially in the order in which they are defined, but that can change

          Comment


          • #6
            Left aside the order of tests, if you just want to keep and run some tests in a suite, instead of the old TestCase way:

            public ReservationServiceUTest(String testname)
            {
            super(testname);
            }

            you can construct your test as following:

            public ReservationServiceIgTest(String testname)
            {
            super();
            this.setName(testname);
            }

            I' m using this for test suites of AbstractDependencyInjectionSpringContextTests class which inherits from TestCase the setName method.
            Since AbstractTransactionalSpringContextTests also inherits from AbstractDependencyInjectionSpringContextTests I think you can work it out the same way

            Comment


            • #7
              Take a look at the book Junit Recipes (if you can) as it explains a lot of nice trick when using JUnits including test ordering.

              Comment

              Working...
              X