class_test 1.0.1 copy "class_test: ^1.0.1" to clipboard
class_test: ^1.0.1 copied to clipboard

discontinued

Allows structuring flutter tests using classes instead of functions to simplify polymorphism testing.

example/example.dart

import 'package:class_test/class_test.dart';
import 'package:flutter_test/flutter_test.dart';

abstract class Animal {
  String get kingdom;
  String get order;
  String get family;
}

class Dog implements Animal {
  String get kingdom => 'Animalia';
  String get order => 'Carnivora';
  String get family => 'Canidae';
}

class Cat implements Animal {
  String get kingdom => 'Animalia';
  String get order => 'Carnivora';
  String get family => 'Felidae';
}



abstract class AnimalTest extends Test {
  Animal animal;

  AnimalTest(this.animal, String name): super(name);

  @override
  void declareTests() {
    declareTest('belongs to Animalia kingdom', () {
      expect(animal.kingdom, 'Animalia');
    });
    declareTest('belongs to Carnivora order', () {
      expect(animal.order, 'Carnivora');
    });
  }
}

class DogTest extends AnimalTest {
  DogTest(): super(Dog(), 'Dog');

  @override
  void declareTests() {
    super.declareTests();
    declareTest('belongs to Canidae family', () {
      expect(animal.family, 'Canidae');
    });
  }
}

class CatTest extends AnimalTest {
  CatTest(): super(Cat(), 'Cat');

  @override
  void declareTests() {
    super.declareTests();
    declareTest('belongs to Felidae family', () {
      expect(animal.family, 'Felidae');
    });
  }
}

void main() {
  DogTest().run();
  CatTest().run();
}
0
likes
40
pub points
0%
popularity

Publisher

unverified uploader

Allows structuring flutter tests using classes instead of functions to simplify polymorphism testing.

Repository (GitHub)
View/report issues

License

Apache-2.0 (LICENSE)

Dependencies

flutter, flutter_test

More

Packages that depend on class_test