wix / Detox

Gray box end-to-end testing and automation framework for mobile apps
https://wix.github.io/Detox/
MIT License
11.16k stars 1.92k forks source link

Enhanced mocking mechanism #2650

Closed whalemare closed 3 years ago

whalemare commented 3 years ago

Is your feature request related to a problem? Please describe. As developer, I like when my tests predictable and reproducible. Detox giving to us great instruments for making taps, swipes, screenshots and other stuff that really helps with e2e tests. But missing one part of mocking, for achieve reproducibility.

I want to make my per test environment unique for this test case. If I check errors, I want to mock all my requests to errors. For achieve this, I want to change implementation of my Service or Repository as I can do it with Jest.

But Detox is gray-box testing tool and can get to us mocking only via metro bundler tool (taking *e2e.ts files instead original), that not usable solution when you need test more that 1 test case.

Describe the solution you'd like I want to get access to my runtime code, for change implementation of some services (for mocking some js part or native module implementations). In native android development, we can do it with help of DI tools (like Dagger solutions here). I want to get the same mechanism of mocking in Detox

test('should show mock message', () => {
  MyDiTool.register({
    messageProvider: () => "Mocked message"
  })
  await expect(element(by.id('text'))).toHaveText("Mocked message");
})

Describe alternatives you've considered

  1. In Dagger + Espresso (on native Android) it could be done
d4vidi commented 3 years ago

@whalemare that would make a wonderful API, but I don't see how it can be technically possible, as the bundle/mocking is usually set up ahead of time (i.e. before the test execution even begins).

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you believe the issue is still relevant, please test on the latest Detox and report back.

Thank you for your contributions!

For more information on bots in this reporsitory, read this discussion.

stale[bot] commented 3 years ago

The issue has been closed for inactivity.