This content has been marked as final.
Show 1 reply
-
1. Re: jMock injection
rafaelri Aug 20, 2010 9:49 AM (in response to agattik)Sorry for not answering that fast but... it might help others...
we found a solution here that works fine...
Suppose you have a CustomerDAO in your src/main folder under com.my.customer.CustomerDAO...
Code a MockCustomerDAO on your src/test folder under the same package as followspublic class MockCustomerDAO { public static CustomerDAO customerDAO; @Unwrap public CustomerDAO getCustomerDAO() { return customerDAO; } }
The tricks are:
- Dont annotate the Mock class otherwise if you are using WTP and run it directly you'll get your mock class instead of your real class
- declare a static field and let seam inject this instance instead of the Mock Class using the @Unwrap annotation
The next step is to configure the mock component with the same name of the real annotated component on the components.xml under src/test/resources with the mock precedence of 40.
This solution follows the premise that your test suite will load the components.xml under src/test/resources/WEB-INF and your development Tomcat on WTP will use src/main/resources.
Hope this helps,
regards,
Rafael Ribeiro