How can I write a test to wait for close app using Flutter Driver

888 Views Asked by At

I have to test my agreement when the app is first launched: if the user do not agree, than the app must close.

Most of the test are already working but I couldn't figure out how to test if the app has closed.

Is there any way to test this behavior and "expect for close app"?

Thanks, Ian

2

There are 2 best solutions below

0
On
  1. Run the app
  2. Initialise flutter driver.
  3. Check that flutter driver is not null
  4. Close the app (the app should be closed and not backgrounded)
  5. driver.checkHealth
0
On

When you trigger app exit you may verify if the app was exited by its exit code

expect(exitCode, 0);

I am using this approach in my tests and it works great.

usage in a sample test: https://github.com/maheshmnj/navbar_router/blob/885c68ae974250167df3c1dccee3e6474f5ddd39/test/navbar_router_test.dart#L210