Skip to content
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

Injected beans not supported in NativeImageTest #110

Closed
tthvo opened this issue Jun 6, 2022 · 3 comments · Fixed by #112
Closed

Injected beans not supported in NativeImageTest #110

tthvo opened this issue Jun 6, 2022 · 3 comments · Fixed by #112
Assignees
Labels
bug Something isn't working test

Comments

@tthvo
Copy link
Member

tthvo commented Jun 6, 2022

It seems adding mock in QuarkusTest breaks the NativeImageTest as it said injected field returns null.

[ERROR] Errors: 
[ERROR]   NativeDatasourceIT>DatasouceTest.testDeleteAllFiles:634 » NullPointer
[ERROR]   NativeDatasourceIT>DatasouceTest.testDeleteAllIOFail:735 » NullPointer
[ERROR]   NativeDatasourceIT>DatasouceTest.testDeleteFileExist:443 » NullPointer
[ERROR]   NativeDatasourceIT>DatasouceTest.testDeleteFileIOFail:563 » NullPointer
[ERROR]   NativeDatasourceIT>DatasouceTest.testDeleteFileNotExist:518 » NullPointer
[ERROR]   NativeDatasourceIT>DatasouceTest.testGetList:174 » NullPointer
[ERROR]   NativeDatasourceIT>DatasouceTest.testGetListEmpty:260 » NullPointer
[ERROR]   NativeDatasourceIT>DatasouceTest.testGetSearch:316 » NullPointer
[ERROR]   NativeDatasourceIT>DatasouceTest.testPostLoad:133 » NullPointer
[ERROR]   NativeDatasourceIT>DatasouceTest.testPostQueryTable:399 » NullPointer
[ERROR]   NativeDatasourceIT>DatasouceTest.testPostQueryTimeseries:355 » NullPointer
[ERROR]   NativeDatasourceIT>DatasouceTest.testPostSet:92 » NullPointer
[ERROR]   NativeDatasourceIT>DatasouceTest.testPostUpload:54 » NullPointer

I read the documentation. Here is what they say.

This also means that injection of beans into a test class using @Inject is not supported in native image tests. Such injection is only possible in tests injected with @QuarkusTest so the test class structure must take this into account.

Is there a way to work around it or should we have a separate test class NativeDatasourceIT for native image instead of extending the base DatasouceTest?

@tthvo tthvo added bug Something isn't working test labels Jun 6, 2022
@tthvo tthvo moved this to Todo in 2.2.0 Release Jun 6, 2022
@tthvo
Copy link
Member Author

tthvo commented Jun 6, 2022

@andrewazores any suggestions?

@tthvo tthvo removed this from 2.2.0 Release Jun 6, 2022
@andrewazores
Copy link
Member

That's unfortunate. I think having a separate NativeDatasourceIT that does not extend the base DatasourceTest sounds good. The native-specific test can't have the mock(s) injected and so the tests can't cover all of the behaviour in the same way, so it will be missing the IOException/HTTP 500 tests for example, but it would be good to at least have tests to verify that it does behave as expected in the "happy path" scenarios.

@tthvo
Copy link
Member Author

tthvo commented Jun 6, 2022

Yes sure! I will fix this while migrating Quarkus in the other issue! Would there be any solution to trigger HTTP 500 on these tests anytime or mock is the only way?

@tthvo tthvo self-assigned this Jun 6, 2022
@tthvo tthvo moved this to Todo in 2.2.0 Release Jun 6, 2022
@andrewazores andrewazores moved this from Todo to In Progress in 2.2.0 Release Jun 7, 2022
Repository owner moved this from In Progress to Done in 2.2.0 Release Jun 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working test
Projects
No open projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants