approval_tests 0.0.7-dev copy "approval_tests: ^0.0.7-dev" to clipboard
approval_tests: ^0.0.7-dev copied to clipboard

Approval Tests implementation in Dart. Inspired by ApprovalTests.

Approval Tests implementation in Dart 🚀

📖 About #

I want to write, and am writing an implementation of a great tool like Approval Tests in Dart. If anyone wants to help, please text me. 🙏

📦 Installation #

Add the following to your pubspec.yaml file:

dependencies:
  approval_tests: ^0.0.7-dev

📚 How to use #

Comparators #

You can use different comparators to compare files. The default is CommandLineComparator which compares files in the console.

To use IDEComparator you just need to add it to options:

 options: const Options(
   comparator: IDEComparator(
      ide: ComparatorIDE.visualStudioCode,
   ),
 ),

But before you add an IDEComparator you need to do the initial customization:

  • Visual Studio Code

    • For this method to work, you need to have Visual Studio Code installed on your machine.
    • And you need to have the code command available in your terminal.
    • To enable the code command, press Cmd + Shift + P and type Shell Command: Install 'code' command in PATH.
  • IntelliJ IDEA

    • For this method to work, you need to have IntelliJ IDEA installed on your machine.
    • And you need to have the idea command available in your terminal.
    • To enable the idea command, you need to create the command-line launcher using Tools - Create Command-line Launcher in IntelliJ IDEA.
  • Android Studio

    • For this method to work, you need to have Android Studio installed on your machine.
    • And you need to have the studio command available in your terminal.
    • To enable the studio command, you need to create the command-line launcher using Tools - Create Command-line Launcher in Android Studio.

📝 Examples #

JSON example #

import 'package:approval_tests/approval_dart.dart';
import 'package:test/test.dart';

void main() {
  group('Approval Tests for Complex Objects', () {
    test('test complex JSON object', () {
      var complexObject = {
        'name': 'JsonTest',
        'features': ['Testing', 'JSON'],
        'version': 0.1,
      };
      ApprovalTests.verifyAsJson(complexObject);
    });
  });
}

Gilded Rose #

void main() {
  // Define all test cases
  const allTestCases = [
    ["foo", "Aged Brie", "Backstage passes to a TAFKAL80ETC concert", "Sulfuras, Hand of Ragnaros"],
    [-1, 0, 5, 6, 10, 11],
    [-1, 0, 1, 49, 50]
  ];

  group('Approval Tests for Gilded Rose', () {
    test('should verify all combinations of test cases', () {
      // Perform the verification for all combinations
      ApprovalTests.verifyAllCombinations(
        inputs: allTestCases,
        options: const Options(
          comparator: IDEComparator(
            ide: ComparatorIDE.visualStudioCode,
          ),
        ),
        processor: processItemCombination,
        file: "example/gilded_rose/test/approved_results/test",
      );
    });
  });
}

// Function to process each combination and generate output for verification
String processItemCombination(Iterable<List<dynamic>> combinations) {
  final receivedBuffer = StringBuffer();

  for (var combination in combinations) {
    // Extract data from the current combination
    String itemName = combination[0];
    int sellIn = combination[1];
    int quality = combination[2];

    // Create an Item object representing the current combination
    Item testItem = Item(itemName, sellIn: sellIn, quality: quality);

    // Passing testItem to the application
    GildedRose app = GildedRose(items: [testItem]);

    // Updating quality of testItem
    app.updateQuality();

    // Adding the updated item to expectedItems
    receivedBuffer.writeln(testItem.toString());
  }

  // Return a string representation of the updated item
  return receivedBuffer.toString();
}

🤝 Contributing #


Show some 💙 and star the repo to support the project! 🙌




Pub License: MIT Repository views Pub

Pub likes Pub popularity Pub points



Thanks to all contributors of this package


20
likes
0
pub points
27%
popularity

Publisher

verified publishershodev.live

Approval Tests implementation in Dart. Inspired by ApprovalTests.

Homepage
Repository (GitHub)
View/report issues

Topics

#testing #approval #approvals #tests #approval-tests

License

unknown (license)

Dependencies

talker, test

More

Packages that depend on approval_tests