-
Notifications
You must be signed in to change notification settings - Fork 86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Documentation for testing #184
Comments
No, there is currently no documentation for something like this. You could try to use the rule API directly in your tests, but I'm not sure if this will easy to do. You could create a testing RewriteEvent and call the methods manually. It's worth a try. However, I think integration tests would be a better way to test something like this. By the way. If you just want to test a Constraint<?>, you can simply refactor the creation of the constraint instance to a method and then use this method to get the configured constraint in your test which then could call the API directly. |
I don't want to test a Constraint<?>, I want to test the rules themselves. As I mentioned "what I want to do is provide a mock for the constrainedBy condition and check whether my rules are working properly".
Well, I have no idea how the internals work, so I am not able to do such thing. Unit testing is a very useful feature when you want to test your rules inside the app without having to restart the server and test each rule every time. Integration tests does not work for me, if I am supposed to use Arquillian I should not use in the main project because there are several dependencies and the internal codebase is always changing (too much mocking maintenance). I should instead create a separate project, but the rewrite rules are related to the business and I have EJB calls inside my Unit testing the Any thoughts? |
Yeah, I agree that unit testing rules may be very useful if you have very complex rules. If you want to understand how the Rule API is used internally, I suggest to have a look at this method: rewrite/impl-servlet/src/main/java/org/ocpsoft/rewrite/servlet/impl/DefaultHttpRewriteProvider.java Line 100 in c960607
This method basically does this:
So if you want to unit test your rules, you could do the following: Just manually create an instance of Then you could write some code that basically does the same as the method I referenced above:
Now you should be able to verify the desired behavior on the mocked servlet objects. |
Hi, I want to unit test my ConfiguratorProviders without inspecting the application behavior. Let's say I create a complex rule with a complex
constrainedBy
condition, what I want to do is provide a mock for theconstrainedBy
condition and check whether my rules are working properly. It helps to avoid regression without the need to check the application behavior every time I make a change.Is there any docs for doing this?
The text was updated successfully, but these errors were encountered: