Skip to content

refactor(libanki): add libanki:testutils#18862

Merged
david-allison merged 2 commits intoankidroid:mainfrom
david-allison:libanki-testclass-3
Jul 18, 2025
Merged

refactor(libanki): add libanki:testutils#18862
david-allison merged 2 commits intoankidroid:mainfrom
david-allison:libanki-testclass-3

Conversation

@david-allison
Copy link
Member

I split this out from #18813 to make it an easier review


  • test modules can't depend on each other
  • We need libanki specific test utilities in both:
    • libanki/test
    • AnkiDroid/test

These utilities are mostly:

  • TestClass: a unit test with access to the Anki Collection
    • And a number of instance methods (soon to be extension methods)
  • A TestClass will have a TestCollectionManager, which is the first interface which we extract in this PR
    • This allows a 'near-pure JVM' instance in libanki using an in-memory collection
    • A standard CollectionManager will be available, if the disk is required

Checklist

  • You have a descriptive commit message with a short title (first line, max 50 chars).
  • You have commented your code, particularly in hard-to-understand areas
  • You have performed a self-review of your own code
  • UI changes: include screenshots of all affected screens (in particular showing any new or changed strings)
  • UI Changes: You have tested your change using the Google Accessibility Scanner

This is for test extensions to `libanki` (depending on `col`)
which are used in both `libanki` and `AnkiDroid` tests

These have an `anki` dependency, but no strong `android` dependencies

Primarily: `TestClass`, but also a number of methods which
 have neither an Android nor an AnkiDroid dependency

These can't exist in `libanki` tests, as you can't depend on test modules
These shouldn't exist in `libanki`, as they should only be visible to
test modules
Copy link
Member

@mikehardy mikehardy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay

@mikehardy mikehardy added Needs Second Approval Has one approval, one more approval to merge and removed Needs Review labels Jul 13, 2025
@david-allison david-allison reopened this Jul 16, 2025
@Arthur-Milchior
Copy link
Member

I'd just like some javadoc on the new interface. Even it only is @see CollectionManager.methodName so that android studio can show useful documentation.

In particular, i must admit i've little intuition of what you'd do with the backend method

Once documented fell free to merge

@david-allison
Copy link
Member Author

david-allison commented Jul 18, 2025

@Arthur-Milchior As this is in a module which does not depend on AnkiDroid, we don't have a reference to CollectionManager, I've tweaked & copied the documentation instead.

  • I removed getColUnsafe: not used in TestClass itself
  • I removed setTestDispatcher and instead implemented it in JvmTest/RobolectricTest
  • discardBackend was documented

allow us to move `TestClass` to `libanki:testutils`
@david-allison david-allison enabled auto-merge July 18, 2025 04:18
@david-allison david-allison added Pending Merge Things with approval that are waiting future merge (e.g. targets a future release, CI wait, etc) and removed Needs Second Approval Has one approval, one more approval to merge labels Jul 18, 2025
@david-allison david-allison added this pull request to the merge queue Jul 18, 2025
Merged via the queue into ankidroid:main with commit 41cfb5f Jul 18, 2025
10 checks passed
@github-actions github-actions bot added this to the 2.22 release milestone Jul 18, 2025
@github-actions github-actions bot removed the Pending Merge Things with approval that are waiting future merge (e.g. targets a future release, CI wait, etc) label Jul 18, 2025
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

Successfully merging this pull request may close these issues.

3 participants