A flutter package with classes to help testing applications using the canvas

Overview

Canvas test helpers

MockCanvas is a utility class for writing tests for canvas operations. It supports the same API as the regular Canvas class from dart:ui (in theory; any missing commands can be added as the need arises). In addition, this class is also a Matcher, allowing it to be used in expect() calls as can be seen in the example below.

Two mock canvases will match only if they have the same number of commands, and if each pair of corresponding commands matches.

Multiple transform commands (translate(), scale(), rotate() and transform()) that are issued in a row are always joined into a single combined transform. Thus, for example, calling translate(10, 10) and then translate(30, -10) will match a single call translate(40, 0).

Some commands can be partially specified. For example, in drawLine() and drawRect() the paint argument is optional. If provided, it will be checked against the actual Paint used, but if omitted, the match will still succeed.

Commands that involve numeric components (i.e. coordinates, dimensions, etc) will be matched approximately, with the default absolute tolerance of 1e-10.

Example Usage

final canvas = MockCanvas();
// ... draw something on the canvas
// then check that the commands issued were the ones that you'd expect:
expect(
  canvas,
  MockCanvas()
    ..translate(10, 10)
    ..drawRect(const Rect.fromLTWH(0, 0, 100, 100)),
);
You might also like...

A mobile map based application to help people everywhere around the world get help

Wonder This is a mobile application made by flutter. The application is called "Wonder" because it will help people everywhere around the world to get

Dec 2, 2021

Flutter package to help you lazily load and display pages of items as the user scrolls down your screen.

Flutter package to help you lazily load and display pages of items as the user scrolls down your screen.

Flutter package to help you lazily load and display pages of items as the user scrolls down your screen.

Dec 13, 2022

A simple package to help does handler with countries in Flutter

A simple package to help does handler with countries in Flutter

It's a simple package to help does handler with countries in [Dart] language and [Flutter] Framework. Usage Countries class Can access all countries s

Feb 20, 2022

A dart package to help you parse and evaluate infix mathematical expressions into their prefix and postfix notations.

A dart package to help you parse and evaluate infix mathematical expressions into their prefix and postfix notations.

Jan 28, 2022

An extension to the Flutter SDK for building Flutter applications for Tizen devices.

An extension to the Flutter SDK for building Flutter applications for Tizen devices.

Flutter for Tizen An extension to the Flutter SDK for building Flutter applications for Tizen devices. Flutter and the related logo are trademarks of

Dec 16, 2022

Environment specific config generator for Dart and Flutter applications during CI/CD builds

Environment Config Generator Environment specific config generator. Allows to specify env configuration during CI/CD build. Primarily created to simpl

Dec 2, 2022

A cli tool to run Flutter applications and auto hot reload it when files are changed

Dashmon A minimalistic CLI tool to run Flutter applications and auto hot reload it when files are changed. It will watch changes your application code

Oct 6, 2022

A simple command-line application to generate simple folder and file structure for Flutter Applications

A simple command-line application to generate simple folder and file structure for Flutter Applications

Kanza_cli is a simple command line tool to generate folder and file structure for your Flutter apps. To use it, you should do the followings: 1. First

Dec 16, 2022

Mustang: A framework to build Flutter applications

Mustang: A framework to build Flutter applications

Mustang A framework to build Flutter applications. Following features are available out of the box. State Management Persistence Cache File layout and

Oct 26, 2022
Comments
  • Implement save and restore functions on mock canvas so their effects can be tested

    Implement save and restore functions on mock canvas so their effects can be tested

    I'm writing a PR on flame to fix an issue I found where components are not properly rendered in priority order if they are HUD. Since that involves checking if the camera is applied or not, I am modifying this so that not only the save/restore count as number is saved, but the transformations are actually applied.

    This has small implications to all our other existing tests, basically because of two things:

    1. we always clear up the camera at the end of the render phase, which requires a new assertion for tests using matchExactly: before:
     .. camera is set
     .. your render checks
    

    after:

     .. camera is set
     .. your render checks
     .. camera is cleared
    
    1. since we collapse adjacent transform operations, in some camera tests we were not actually rendering any component, and just checking that the camera transform is applied; however due to the collapse and my optimization on the render flow, the camera was no longer applied needlessly, so all camera tests had to be modified to actually have a component (most already had)

    For the context of how this is used, check https://github.com/flame-engine/flame/pull/1148

    opened by luanpotter 0
Releases(0.1.1)
Owner
Blue Fire
Team working on open source packages and plugins for Flutter, like Flame, Audioplayers, Photo View among others.
Blue Fire
A CLI tool to help generate dart classes from json returned from API

Json 2 Dart Command line utility Important note There is already a package called json2dart so this package will be called json2dartc ! This project w

Adib Mohsin 38 Oct 5, 2022
An auto mapper for Dart. It allows mapping objects of different classes automatically and manually using JSON serialization.

AutoMapper for Dart An auto mapper for Dart. It allows mapping objects of different classes automatically and manually using JSON serialization. Examp

Leynier Gutiérrez González 7 Aug 24, 2022
Flutter library to add gestures and animations to each Shape you draw on your canvas in your CustomPainter

Flutter library to bring your CustomPainter ?? to Life ✨ ⚡️ touchable library gives you the ability to add various gestures and animations to each Sha

Natesh Bhat 190 Jan 7, 2023
Renders a wavefront .obj on to a canvas.

flutter_3d_obj A flutter package to render wavefront obj files on a canvas. Usage To use this package, add flutter_3d_obj to your pubspec.yaml file. T

Hemanth Raj V 146 Nov 3, 2022
Auto is a Flutter automated testing framework developed for testers.

Auto Auto-A simpler Flutter UI automation test solution. No need to write any code Recording test scripts is very simple Mult

null 19 Oct 12, 2022
How to use the Robot Testing pattern in Flutter

Robot Testing Pattern in Flutter Developed with ?? by Very Good Ventures ?? This project showcases how to apply the Robot Testing pattern to a Flutter

Very Good Ventures 38 Dec 16, 2022
Automatically generate usecase classes from your repository class definition in Dart and Flutter

Repo Case Automatically generate usecase classes from your repository class definition in Dart and Flutter. Check out the official guide on repo_case

Sandro Maglione 5 Jul 30, 2022
Dart Code Generator for generating mapper classes

Smartstruct - Dart bean mappings - the easy nullsafe way! Code generator for generating type-safe mappers in dart, inspired by https://mapstruct.org/

Nils 28 Nov 29, 2022
A Dart testing utility for asserting that some code emits a compilation error.

A Dart testing utility for asserting that some code emits a compilation error.

Remi Rousselet 32 Dec 11, 2022
Contains utility functions and classes in the style of dart:collection to make working with collections easier

The collection package for Dart contains a number of separate libraries with utility functions and classes that makes working with collections easier.

Dart 273 Dec 27, 2022