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

Use DB mocking for tests that require BETY? #3066

Open
Aariq opened this issue Nov 14, 2022 · 3 comments
Open

Use DB mocking for tests that require BETY? #3066

Aariq opened this issue Nov 14, 2022 · 3 comments

Comments

@Aariq
Copy link
Collaborator

Aariq commented Nov 14, 2022

Description

Tests for some packages fail in environments without access to BETYdb. E.g. PEcAn.BIOCRO.

Proposed Solution

I'm familiar with "webmocking", where requests to an API are stored and then used to simulate future API calls for unit tests without the necessity for a internet connection. A preliminary search for database mocking turned up with dittodb, an rOpenSci package inspired by httrtest (for webmocking) but for mocking database connections. Using database mocking with tests would help make PEcAn packages more modular and would be necessary for passing unit tests for CRAN.

Alternatives

  • Skip these failing tests on CI and CRAN and rely on PEcAn's integration tests (not 100% sure how these work)?
  • Write a custom function / data to stand up a minimal database to use for testing
  • Use a more general (but harder to use) mocking package like mockery
@meetagrawal09
Copy link
Collaborator

The logs of PEcAn.BIOCRO seem to have expired.
So is the failing test being talked about here in PEcAn.BIOCRO package present in this file : Link ?

@infotroph
Copy link
Member

infotroph commented Feb 4, 2023

@meetagrawal09 Yes, that's the one.

A lot of the complexity in that file is my fault (from 5 years ago now!) -- feel free to ask me me questions about it as needed. It may be obvious, but in case: Note that there are two separate kinds of mocking at play here.

  • the settings object expects to contain a live database connection that will be used inside the run.biocro call. This is the thing @Aariq is proposing to mock.
  • The calls to mock_result are trying to keep the tests working after I added some /very/ hacky internal code to support two very different versions of the BioCro model. We may want to consider sunsetting support for the older version, but that's a separate project.

(^all of that applies only to this particular BioCro test, not to bety-dependent tests in other packages)

@Laiba-zaheer20
Copy link

@Aariq , I would like to work on this.

@Aariq Aariq assigned Aariq and Laiba-zaheer20 and unassigned Aariq and Laiba-zaheer20 Dec 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants