5 Replies Latest reply on Jan 12, 2010 11:14 AM by Peter Royle

    Weld, TDD and Weld Test

    Drew Arrigoni Newbie

      I'm trying out TDD for the first time (Go n00b powaa!) and I have a few questions:


      1) I've read in a couple of places that a Weld unit testing framework was/is in the works. Where can I follow this project?


      2) Assuming the above isn't in a usable state, are there any work arounds?


      3) I'm taking advantage of Bean Validation and Hibernate Validators. Is there a good way to invoke this validation before passing the bean into a business fuction?


      4) I know that Bean Validation can be triggered automatically with JSF2 and JPA. Is there anything special I need to use to trigger these things? Will they work in a testing environment?


      5) Are there any other things that I should know about regarding Weld, J2EE6 and TDD?



      Thanks in advance for any help!

        • 1. Re: Weld, TDD and Weld Test
          Gavin King Master

          You don't need any special framework to unit test your CDI beans! Or do you mean integration testing?

          • 2. Re: Weld, TDD and Weld Test
            Drew Arrigoni Newbie

            googles the difference I guess?


            If a given function on a service invokes another service, and that service needs to be injected, is that a unit test or an integration test?

            • 3. Re: Weld, TDD and Weld Test
              Gavin King Master

              By the strictest definition of unit test, a unit test is a test of the unit, i.e. the class, in isolation. Now, I don't think that this kind of test is very useful at all (since it doesn't test anything about the true system requirements), and even worse it makes the code more difficult to refactor (since you have to change your tests for minor refactoring tasks).


              However, in practice, I think a lot of people write unit tests that actually test the interactions between several classes, and in this case, yes, services need to be injected. But they don't need to be injected by CDI. You can inject them by calling the constructor or initializer method yourself.


              I don't think unit test is a good word to use for tests which involve the container. I call these integration tests, though that term may also be incorrect. For this kind of test, the Weld Java SE extension will probably get you quite far, but yes, we are working on something better.


              (Yes, I know a lot of people use unit test to refer to any kind of automated test, but I think this is a very confusing usage.)

              • 4. Re: Weld, TDD and Weld Test
                Drew Arrigoni Newbie

                For this kind of test, the Weld Java SE extension will probably get you quite far, but yes, we are working on something better.


                Cool. I found this while googling on how to implement this but I'm not sure what CDIRunner would do and the link seems to be broken.

                • 5. Re: Weld, TDD and Weld Test
                  Peter Royle Newbie

                  If you'd like to try the pure Weld SE approach, here's an example TestNG test for reference.