-
Notifications
You must be signed in to change notification settings - Fork 951
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
Mock Service | Grails 5.3.3 #13506
Comments
Similar issue is about DataSource.
Data source is a nested bean far down the hierarchy of beans. Running a Unit Test, i am just expecting a UNIT peace of code to be tested. No need for data source or loading all the beans of the application. |
Hello, unfortunately no. |
That is interesting. Are you using Gradle to run the test? This is what I am seeing: https://gist.github.com/osscontributor/1786f4cce7e73aa943f3f6fc479fc4b4 |
I have tried a few combinations of class dependencies and I haven't yet been able to reproduce the problem. If you could send a PR to the repo I linked above with a combination of things that recreates the problem, that would prove helpful in troubleshooting. |
Maybe let me paraphrase the question. @osscontributor how do you mock or configure DataSource for unit tests? |
If you are using GORM, you generally wouldn't. The more common thing is to kind of mock GORM using the default implementation that is configured in unit tests which uses a Map backed store. It is unusual for a controller to interact directly with a DataSource. If you can provide a sample app which demonstrates what you are trying to test I would be happy to send you a PR or identify if there is relevant bug in the framework. Thank you for the feedback. |
Hello @osscontributor |
@urmichm Can you share a link to a sample project which demonstrates the problem? |
I assume that it might be that you are calling another controller from the one under unit test. But, if could share the code which is unit tested here or better a sample application that'd be helpful to debug the issue. Generally, you would mock any service which is being called from the controller. Let's walk through an example:
Please note that above examples are only for reference. I didn't get the chance to verify this manually but would need to mock things as per the application and the specific services, methods, or contructors. |
Expected Behavior
When running unit test on a controller
I need to run unit tests for the controller
Actual Behaviour
Exception
Steps To Reproduce
Environment Information
Ububntu
java 1.8
Example Application
No response
Version
5.3.3
The text was updated successfully, but these errors were encountered: