dante
dante

Reputation: 1254

Flutter test: The value of a foundation debug variable was changed by the test

When I run my integration test, the test failed with this error:

[+1358 ms] flutter: ══╡ EXCEPTION CAUGHT BY FLUTTER TEST FRAMEWORK ╞════════════════════════════════════════════════════
[        ] flutter: The following assertion was thrown running a test:
[        ] flutter: The value of a foundation debug variable was changed by the test.
[        ] flutter: 
[        ] flutter: When the exception was thrown, this was the stack:
[        ] flutter: #0      debugAssertAllFoundationVarsUnset.<anonymous closure> (package:flutter/src/foundation/debug.dart:30:7)
[        ] flutter: #1      debugAssertAllFoundationVarsUnset (package:flutter/src/foundation/debug.dart:32:4)
[        ] flutter: #2      TestWidgetsFlutterBinding._verifyInvariants (package:flutter_test/src/binding.dart:834:12)
[        ] flutter: #3      TestWidgetsFlutterBinding._runTestBody (package:flutter_test/src/binding.dart:821:7)
[        ] flutter: <asynchronous suspension>
[        ] flutter: 
[        ] flutter: The test description was:

When I debug into the exception, I found that this checkpoint is failed:

debugDefaultTargetPlatformOverride != null  // it is TargetPlatform.macos

I'm not sure how to deal with this error. The value can be changed everywhere and it make my test fail. Any solution or workaround?

Upvotes: 3

Views: 1832

Answers (1)

Jan-Stepien
Jan-Stepien

Reputation: 523

Had the same, my solution was:

You have to set the TargetPlatform to null before finishing of tests

 debugDefaultTargetPlatformOverride = TargetPlatform.iOS;

//  HERE RUN YOUR TESTS AND CHECKS

debugDefaultTargetPlatformOverride = null;

Upvotes: 8

Related Questions