given_when_then_unit_test 0.0.2 copy "given_when_then_unit_test: ^0.0.2" to clipboard
given_when_then_unit_test: ^0.0.2 copied to clipboard

outdated

A package to make Unit Test code more readable and well documented.

example/lib/example.dart

// ignore_for_file: public_member_api_docs

import 'package:given_when_then_unit_test/given_when_then_unit_test.dart';
import 'package:shouldly/shouldly.dart';
import 'package:test/test.dart';

class Calculator {
  num _val = 0;
  num get res => _val;

  void add(num value) {
    _val = _val + value;
  }

  void subtract(int value) {
    _val = _val - value;
  }
}

void main() {
  group('calculator', () {
    late Calculator calc;

    setUp(() {
      calc = Calculator();
    });

    when('add 1', () {
      setUp(() => calc.add(1));

      test('result should be 1', () {
        calc.res.should.be(1);
      });

      group('[and] substract 1', () {
        setUp(() => calc.subtract(1));
        test('res should be 0', () {
          calc.res.should.beZero();
        });
      });
    });
  });

  given('calculator', () {
    late Calculator calc;

    before(() {
      calc = Calculator();
    });

    when('add 1', () {
      before(() => calc.add(1));

      then('result should be 1', () {
        calc.res.should.be(1);
      });

      when('[and] subtract 1', () {
        before(() => calc.subtract(1));
        then('res should be 0', () {
          calc.res.should.beZero();
        });
      });
    });
  });
}
19
likes
0
pub points
68%
popularity

Publisher

verified publisherdevcraft.ninja

A package to make Unit Test code more readable and well documented.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

meta, test

More

Packages that depend on given_when_then_unit_test