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

feat: Allow LooperMode annotation on nested tests and test methods #59

Merged
merged 2 commits into from
May 9, 2024

Conversation

warnyul
Copy link
Member

@warnyul warnyul commented May 9, 2024

Summary by CodeRabbit

  • Documentation
    • Updated the limitations section in the README to clarify experimental support for parallel test execution and restrictions on annotations within test classes.
  • Bug Fixes
    • Enhanced the stability and performance of test execution by refining synchronization and parameter handling in internal test runner methods.
  • New Features
    • Introduced new test methods with specific LooperMode settings to verify thread behavior in a Robolectric test environment.

@warnyul warnyul self-assigned this May 9, 2024
Copy link
Contributor

coderabbitai bot commented May 9, 2024

Walkthrough

The recent updates aim to refine Robolectric's testing framework by adjusting annotation usage, enhancing synchronization in test execution, and improving looper management. Changes include clarifying limitations in the README.md, removing looperMode parameter, optimizing method parameters and functionality, and enforcing stricter rules for annotation placement to uphold test integrity.

Changes

File Path Change Summary
README.md Updated limitations on parallel test execution and annotation restrictions.
.../internal/JUnit5RobolectricSandboxManager.kt Removed looperMode from constructor.
.../internal/JUnit5RobolectricTestRunner.kt Improved looper management in runBeforeTest and runFinallyAfterTest methods.
.../internal/JUnit5RobolectricTestRunnerHelper.kt Enhanced runFinallyAfterTest with this parameter.
.../internal/SandboxExtensions.kt Introduced functions to clear and reset the ShadowLooper.
.../internal/validation/TestClassValidator.kt Removed LooperMode import and usage in validation function.
.../robolectric/RobolectricExtensionLooperModeSelfTest.kt Added tests for different LooperMode settings.
.../robolectric/RobolectricExtensionSelfTest.kt Removed testMethod_shouldBeInvoked_onMainThread function.

🐇✨
In the realm of code and byte,
Where tests dance in the moonlight,
A rabbit hops with pure delight,
Looper modes now shine bright.
Changes made with care and might,
Ensuring tests are airtight!
🌟📜


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 7413f6b and 8611dfb.
Files selected for processing (8)
  • README.md (1 hunks)
  • robolectric-extension/src/main/kotlin/tech/apter/junit/jupiter/robolectric/internal/JUnit5RobolectricSandboxManager.kt (2 hunks)
  • robolectric-extension/src/main/kotlin/tech/apter/junit/jupiter/robolectric/internal/JUnit5RobolectricTestRunner.kt (1 hunks)
  • robolectric-extension/src/main/kotlin/tech/apter/junit/jupiter/robolectric/internal/JUnit5RobolectricTestRunnerHelper.kt (1 hunks)
  • robolectric-extension/src/main/kotlin/tech/apter/junit/jupiter/robolectric/internal/SandboxExtensions.kt (1 hunks)
  • robolectric-extension/src/main/kotlin/tech/apter/junit/jupiter/robolectric/internal/validation/TestClassValidator.kt (2 hunks)
  • robolectric-extension/src/test/kotlin/tech/apter/junit/jupiter/robolectric/RobolectricExtensionLooperModeSelfTest.kt (1 hunks)
  • robolectric-extension/src/test/kotlin/tech/apter/junit/jupiter/robolectric/RobolectricExtensionSelfTest.kt (1 hunks)
Files skipped from review due to trivial changes (1)
  • robolectric-extension/src/main/kotlin/tech/apter/junit/jupiter/robolectric/internal/validation/TestClassValidator.kt
Additional Context Used
LanguageTool (4)
README.md (4)

Near line 18: Possible missing comma found.
Context: ...* Parallel Execution: Parallel test execution only experimentally supported with clas...


Near line 21: You might be missing the article “the” here.
Context: ...icsMode` annotations can only be set on outermost test class. * Experimental Status: ...


Near line 123: You might be missing the article “the” here.
Context: ...our test methods. You could also use org.jetbrains.kotlin:kotlin-test-junit5...


Near line 123: This phrasing can be overused. Try elevating your writing with a more formal alternative.
Context: ...ains.kotlin:kotlin-test-junit5` package if you want to.

Kotlin</summa...

Additional comments not posted (7)
robolectric-extension/src/main/kotlin/tech/apter/junit/jupiter/robolectric/internal/SandboxExtensions.kt (2)

44-47: Ensure proper exception handling for reflection use in clearShadowLooperCache.

Reflection is used to clear the looper cache. Consider wrapping this in a try-catch block to handle potential ClassNotFoundException, NoSuchMethodException, or InvocationTargetException that might arise from reflection operations.


49-52: Ensure proper exception handling for reflection use in resetLooper.

Reflection is used to reset the main and thread-specific loopers. Consider wrapping this in a try-catch block to handle potential reflection-related exceptions.

robolectric-extension/src/test/kotlin/tech/apter/junit/jupiter/robolectric/RobolectricExtensionLooperModeSelfTest.kt (1)

1-84: Tests are well-structured and effectively use the new @LooperMode annotations.

The tests in RobolectricExtensionLooperModeSelfTest.kt are comprehensive and well-organized, effectively testing the new functionality related to LooperMode annotations on nested classes and methods.

robolectric-extension/src/main/kotlin/tech/apter/junit/jupiter/robolectric/internal/JUnit5RobolectricTestRunnerHelper.kt (1)

59-59: Change aligns with modifications in the main test runner to ensure correct context passing.

The addition of the this reference in the runFinallyAfterTest method call ensures that the correct sandbox environment is used for cleanup, aligning with the architectural changes made in the main test runner.

robolectric-extension/src/main/kotlin/tech/apter/junit/jupiter/robolectric/internal/JUnit5RobolectricTestRunner.kt (2)

61-62: Enhanced logging in runBeforeTest improves visibility of test execution.

The addition of a logging statement in the runBeforeTest method enhances the visibility and traceability of the test execution process, aiding in debugging and monitoring.


70-74: Enhanced cleanup in runFinallyAfterTest ensures correct test environment reset.

The inclusion of clearShadowLooperCache and resetLooper in the runFinallyAfterTest method ensures that the test environment is correctly reset after each test, enhancing the reliability and consistency of the testing process.

README.md (1)

18-21: Clarify the experimental support for parallel test execution and restrictions on annotations.

The updates in the README.md file clearly explain the experimental support for parallel test execution and the restrictions on setting certain annotations only on the outermost test class. However, consider adding a comma after "execution" in line 18 and inserting "the" before "outermost test class" in line 21 for grammatical correctness.

- Parallel test execution only experimentally supported with classes.
+ Parallel test execution, only experimentally supported with classes.
- annotations can only be set on outermost test class.
+ annotations can only be set on the outermost test class.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 8611dfb and f5ae744.
Files selected for processing (1)
  • robolectric-extension/src/main/kotlin/tech/apter/junit/jupiter/robolectric/internal/JUnit5RobolectricTestRunner.kt (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • robolectric-extension/src/main/kotlin/tech/apter/junit/jupiter/robolectric/internal/JUnit5RobolectricTestRunner.kt

@warnyul warnyul merged commit 9fffee5 into main May 9, 2024
3 checks passed
@warnyul warnyul deleted the loopermode branch May 9, 2024 13:59
@warnyul warnyul added the enhancement New feature or request label May 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant