Two different setUp methods for the same tests

jxmorris12

I currently have two groups of tests that are identical in every way except the setUp() method call. I want to simplify the code so that the set of tests is only defined once but each group runs its own setUp() method and then the identical set of tests.

Currently my code looks something like this:

group('test things while a flag is turned off', () {
  setUp(() {
    global_flags.flag = false;
  }
  /* run lots of tests */
})

group('test things while a flag is turned on' () {
  setUp(() {
    global_flags.flag = true;
  }
  /* run the exact same tests */
}

How can I consolidate this code?

Günter Zöchbauer

You can register the same tests multiple times and add parameters to customize execution:

main() {
  myTests(true);
  myTests(false);
}

myTests(bool global_flags) {
  group('test things while a flag is turned ${global_flags ? 'on' : 'off'}' () {
    /* run the exact same tests */
  });
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Related Related

HotTag

Archive