Description
Description:
Currently, unit tests in Flutter do not provide a straightforward way to access and test native code used within plugins. This limitation forces developers to rely on either:
- Mocking the native code, which doesn't allow for comprehensive and accurate testing of how the app interacts with actual native functionality.
- Integration tests, which are often too slow and focused on testing the app and UI, rather than specific, isolated functions that call native code.
As a result, there is a gap in testing where developers cannot properly validate the integration and behavior of native code in isolation, slowing down development and making it harder to catch issues early in the development cycle.
Problem:
- Mocking native code: While mocking works in some cases, it doesn't properly simulate the native code’s actual behavior, leading to false positives/negatives in tests.
- Slow integration tests: Integration tests, while useful, are generally slow, and focus more on end-to-end behavior (app + UI) rather than unit-level functionality. This makes testing a single function that relies on native code cumbersome and inefficient.
Proposed Solution:
I would like to request a feature where Flutter allows access to plugin code in unit tests, so we can test the native functionality directly in a more isolated and efficient manner.
- This would allow us to write unit tests that can call native functions directly without resorting to mocking.
- It would speed up the testing process by ensuring that we can test native interactions in a controlled environment, without having to rely on slow integration tests that test multiple layers of the application.
Benefits:
- Faster unit tests: Unit tests will run faster since they won't require full integration setups or UI interaction.
- More accurate testing: Testing native code directly will allow us to ensure that our app's native functionality behaves as expected, without the abstraction or inaccuracies introduced by mocking.
- Improved developer experience: The ability to write more fine-grained tests that focus on specific functionality rather than having to test everything end-to-end.
I believe this feature would greatly improve the testing experience in Flutter and enable more reliable testing practices for developers working with native plugins.