Giter Club home page Giter Club logo

Comments (10)

synw avatar synw commented on August 29, 2024

To run the tests with coverage use:

pub run test_coverage --no-badge && genhtml -o coverage coverage/lcov.info

The coverage then can be viewed at coverage/index.html

from sqlcool.

flutteradv avatar flutteradv commented on August 29, 2024

when I run the above command I got following error:
Could not find a file named "pubspec.yaml" in "/Users/MoNa/.pub-cache/hosted/pub.dartlang.org/file-5.0.8+1".
also I can run for regulat POJO unit tests using

flutter test --coverage

for sqlCool unit tests I have to run on device by
flutter run test file
so there is no way to include in coverage report. I saw there is coverage report in this repo how that is done?

from sqlcool.

synw avatar synw commented on August 29, 2024

Yes use:

flutter test --coverage && genhtml coverage/lcov.info -o coverage/output

This is how the coverage report is done

from sqlcool.

flutteradv avatar flutteradv commented on August 29, 2024

but that gives following error:
MissingPluginException(No implementation found for method getApplicationDocumentsDirectory on channel plugins.flutter.io/path_provider)

from sqlcool.

synw avatar synw commented on August 29, 2024

Does this happen when you run flutter test from the main directory of the Sqlcool package ot when running your own tests?

The tests mock the app directory so this is not supposed to happen: https://github.com/synw/sqlcool/blob/master/test/base.dart#L15 : the Db.Γ¬nit method in the tests must always be run with the absolutePath: true parameter to be able to run on a computer and avoid path provider incompatibilities

from sqlcool.

flutteradv avatar flutteradv commented on August 29, 2024

I face the error when running my own tests and here is my test code:

Map item = {
    '@token': mockToken,
    'refreshToken': mockRefreshToken,
    '@time_bubble': '1y',
    '@time_list': '1M',
    "@first_time": 'yes'
  };
  AppModel model = AppModel();
  SharedPreferences prefs = await getReloadedSharedPreferencesInstance();
  Db sql;
  ObjectDB odb;
  sql = Db();
  await sql.init(
      path: "db.sqlite", verbose: true, queries: kAppDatabaseTableQueries);
  model.db = sql;
  model.odb = odb;
  model.init(item, prefs);
test("changeTimeFilter test", () async {
      UserModel userModel = UserModel(
          id: "79cf2048cae6f287b7b8ca271a567129",
          email: "[email protected]",
          title: "anon",
          alias: "AN",
          self:
              "https: //newsconsole.com/test/api/napi2/nodes/79cf2048cae6f287b7b8ca271a567129");
      model.user = userModel;
      await model.changeTimeFilter({"value": "6M", "type": "list"});
      List<Map<String, dynamic>> users_meta =
          await model.db.query("SELECT * FROM users_meta");
      expect(users_meta[0], {
        "id": 1,
        "user_id": "79cf2048cae6f287b7b8ca271a567129",
        "meta_key": "time_filter",
        "meta_value": "6M",
        'updated': null
      });
      model.timeFilterController.stream.last.then((timeMap) {
        expect(timeMap, {"value": "6M", "type": "list"});
      });
    });

    test("setTabsAllowed test", () async {
      UserModel userModel = UserModel(
          id: "79cf2048cae6f287b7b8ca271a567129",
          email: "[email protected]",
          title: "anon",
          alias: "AN",
          self:
              "https: //newsconsole.com/test/api/napi2/nodes/79cf2048cae6f287b7b8ca271a567129");
      model.user = userModel;
      await model.setTabsAllowed(10);
      List<Map<String, dynamic>> users_meta =
          await model.db.query("SELECT * FROM users_meta");
      expect(users_meta.last["meta_value"], '10');
      model.tabsController.stream.last.then((maxTab) {
        expect(maxTab, 10);
      });
    });

How should I mock sqlcool update and query calls for unit tests

from sqlcool.

synw avatar synw commented on August 29, 2024

As the running database in tests is fake you must mock the query results: check channel.setMockMethodCallHandler in https://github.com/synw/sqlcool/blob/master/test/base.dart for how to proceed

Mock everything that is platform specific: I see that you have a reference to shared preferences for example, not sure that this one can run on desktop

from sqlcool.

flutteradv avatar flutteradv commented on August 29, 2024

I have following code to mock prefrences:

Future<SharedPreferences> getReloadedSharedPreferencesInstance() async {
  SharedPreferences.setMockInitialValues({});
  return await SharedPreferences.getInstance()
    ..reload();
}

Should I change the sqflite package to sqlcool in following code:
const MethodChannel channel = MethodChannel('com.tekartik.sqflite');

from sqlcool.

synw avatar synw commented on August 29, 2024

Should I change the sqflite package to sqlcool in following code:
const MethodChannel channel = MethodChannel('com.tekartik.sqflite');

No,keep it: the method channels belong to Sqflite

from sqlcool.

flutteradv avatar flutteradv commented on August 29, 2024

Thanks a lot. I thought I should test db on device which is not possible to include in coverage report

from sqlcool.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.