Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unit Testing #166

Open
SchrodingersGat opened this issue Dec 11, 2024 · 0 comments
Open

Unit Testing #166

SchrodingersGat opened this issue Dec 11, 2024 · 0 comments

Comments

@SchrodingersGat
Copy link

Hi @khoren93 I am wondering if there is a way to run unit tests on known images, as a way to ensure that the barcode scanning functionality does not "regress" across release cycles.

For reference, I am using this library in https://github.com/inventree/inventree-app/

And trying to run the following code in a unit test:

/*
 * Helper function to read a barcode from an image file
 */
Future<zxing.Code> readBarcodeFromImage(String path) async {

  // Load file from provided path
  final XFile imageFile = XFile("test_resources/$path");

  final zxing.DecodeParams params = zxing.DecodeParams(
    imageFormat: zxing.ImageFormat.rgb,
    tryHarder: true,
    tryRotate: true,
    tryInverted: true,
    isMultiScan: false,
  );

  final zxing.Code code = await zxing.zxingReadBarcodeImagePath(imageFile, params);

  debugDefaultTargetPlatformOverride = null;

  return code;
}

void main() {

  TestWidgetsFlutterBinding.ensureInitialized();

  group("Test Barcodes:", () {

    debugDefaultTargetPlatformOverride = TargetPlatform.android;

    test("Code-39", () async {
      final zxing.Code code = await readBarcodeFromImage("code-39.png");

      expect(code, isNotNull);
      expect(code.text, "012345678905");
    });

  });
}

However, I run into this error, I believe because the test is being run on a windows machine, and not respecting the target platform (Android) in this case?

  Invalid argument(s): Failed to load dynamic library 'flutter_zxing.dll': The specified module could not be found.
   (error code: 126)
  dart:ffi                                                   new DynamicLibrary.open
  package:flutter_zxing/src/logic/bindings.dart 10:27        _openDynamicLibrary
  package:flutter_zxing/src/logic/bindings.dart 15:24        dylib
  package:flutter_zxing/src/logic/bindings.dart              dylib
  package:flutter_zxing/src/logic/bindings.dart 3:54         bindings
  package:flutter_zxing/src/logic/bindings.dart              bindings
  package:flutter_zxing/src/logic/barcode_reader.dart 40:5   _readBarcode
  package:flutter_zxing/src/logic/barcode_reader.dart 37:5   zxingReadBarcode
  package:flutter_zxing/src/logic/barcode_reader.dart 18:10  zxingReadBarcodeImagePath
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant