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

Fix Part of #4236 : Add tests for AsyncResultSubject #5670

Open
wants to merge 14 commits into
base: develop
Choose a base branch
from

Conversation

TanishMoral11
Copy link
Collaborator

@TanishMoral11 TanishMoral11 commented Jan 26, 2025

Explanation

Fixes part of #4236: Adds tests to ensure correct handling of non-iterable async results.

This PR adds tests for the AsyncResultSubject class. It verifies that the AsyncResultSubject handles non-iterable results correctly and ensures that the expected failures occur when the result is not iterable. The test specifically checks that the appropriate behavior is triggered when a non-iterable result is provided.

Essential Checklist

  • The PR title and explanation each start with "Fix #bugnum: " (If this PR fixes part of an issue, prefix the title with "Fix part of #bugnum: ...".)
  • Any changes to scripts/assets files have their rationale included in the PR explanation.
  • The PR follows the style guide.
  • The PR does not contain any unnecessary code changes from Android Studio (reference).
  • The PR is made from a branch that's not called "develop" and is up-to-date with "develop".
  • The PR is assigned to the appropriate reviewers (reference).

@TanishMoral11
Copy link
Collaborator Author

Hey @adhiamboperes PTAL, and suggest me if there are any changes to make.

Image

@TanishMoral11 TanishMoral11 marked this pull request as ready for review January 27, 2025 10:48
@TanishMoral11 TanishMoral11 requested review from a team as code owners January 27, 2025 10:48
@TanishMoral11
Copy link
Collaborator Author

Hey @adhiamboperes, PTAL !!

Copy link

Coverage Report

Results

Number of files assessed: 3
Overall Coverage: 89.81%
Coverage Analysis: PASS

Passing coverage

Files with passing code coverage
File Coverage Lines Hit Status Min Required
MathTagHandler.ktutility/src/main/java/org/oppia/android/util/parser/html/MathTagHandler.kt
89.81% 97 / 108 70%

Exempted coverage

Files exempted from coverage
File Exemption Reason
StateRetriever.ktdomain/src/main/java/org/oppia/android/domain/util/StateRetriever.kt
This file is incompatible with code coverage tooling; skipping coverage check.
AsyncResultSubject.kttesting/src/main/java/org/oppia/android/testing/data/AsyncResultSubject.kt
This file is exempted from having a test file; skipping coverage check.

Refer test_file_exemptions.textproto for the comprehensive list of file exemptions and their required coverage percentages.

To learn more, visit the Oppia Android Code Coverage wiki page

Copy link

Coverage Report

Results

Number of files assessed: 1
Overall Coverage: 0.00%
Coverage Analysis: PASS

Exempted coverage

Files exempted from coverage
File Exemption Reason
AsyncResultSubject.kttesting/src/main/java/org/oppia/android/testing/data/AsyncResultSubject.kt
This file is exempted from having a test file; skipping coverage check.

Refer test_file_exemptions.textproto for the comprehensive list of file exemptions and their required coverage percentages.

To learn more, visit the Oppia Android Code Coverage wiki page

@TanishMoral11
Copy link
Collaborator Author

Hey @adhiamboperes , could you please take a look ?

Thanks !!

@adhiamboperes adhiamboperes changed the title Fix #4236 : Add tests for AsyncResultSubject Fix Part of #4236 : Add tests for AsyncResultSubject Jan 30, 2025
Copy link
Collaborator

@adhiamboperes adhiamboperes left a comment

Choose a reason for hiding this comment

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

Thanks @TanishMoral11!
I noticed that you have not fully tested the class. Additionally, please rename the tests following the pattern that I have suggested.

@@ -33,3 +33,21 @@ oppia_android_test(
"//utility/src/main/java/org/oppia/android/util/networking:debug_module",
],
)

# Adding test for AsyncResultSubject
Copy link
Collaborator

Choose a reason for hiding this comment

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

This comment is not required.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

Copy link
Collaborator

Choose a reason for hiding this comment

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

remove this file from test_file_exemptions

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done .

import org.oppia.android.util.data.AsyncResult
import org.robolectric.RobolectricTestRunner

@RunWith(RobolectricTestRunner::class)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
@RunWith(RobolectricTestRunner::class)
@RunWith(JUnit4::class)

class AsyncResultSubjectTest {

@Test
fun testAsyncResultPending_isPending() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
fun testAsyncResultPending_isPending() {
fun testAsyncResultSubject_pendingResult_checkIsPending() {

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

}

@Test
fun testAsyncResultPending_isNotSuccess() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
fun testAsyncResultPending_isNotSuccess() {
fun testAsyncResultSubject_pendingResult_checkIsNotSuccess() {

Copy link
Collaborator

Choose a reason for hiding this comment

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

You are also missing a corresponding "isNotFailure()" test.

Comment on lines 33 to 41
@Test
fun testAsyncResultSuccess_hasSuccessValueWhere_matchesExpected() {
val successResult: AsyncResult<String> = AsyncResult.Success("Success value")

AsyncResultSubject.assertThat(successResult).hasSuccessValueWhere {
// Here we are verifying that the value is "Success value"
assertThat(this).isEqualTo("Success value")
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggestion to reduce ambiguity.

Suggested change
@Test
fun testAsyncResultSuccess_hasSuccessValueWhere_matchesExpected() {
val successResult: AsyncResult<String> = AsyncResult.Success("Success value")
AsyncResultSubject.assertThat(successResult).hasSuccessValueWhere {
// Here we are verifying that the value is "Success value"
assertThat(this).isEqualTo("Success value")
}
}
@Test
fun testAsyncResultSuccess_hasSuccessValueWhere_matchesExpected() {
val successResult: AsyncResult<String> = AsyncResult.Success("Some string")
AsyncResultSubject.assertThat(successResult).hasSuccessValueWhere { result ->
assertThat(result).isEqualTo("Some string")
}
}

Copy link

Coverage Report

Results

Coverage Analysis: SKIP ⏭️

This PR did not introduce any changes to Kotlin source or test files.

To learn more, visit the Oppia Android Code Coverage wiki page

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.

2 participants