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

Fixes #4272: Added Tests for EventLogSubject. #5678

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

Conversation

theayushyadav11
Copy link
Collaborator

@theayushyadav11 theayushyadav11 commented Jan 29, 2025

Fixes #4272:

This pull request introduces new tests for the EventLogSubject class in the Oppia Android project. The main changes include the addition of the EventLogSubjectTest class and the corresponding build configuration updates.

New Tests for EventLogSubject:

Build Configuration Updates:

Code Cleanup:

There are many tests which are remaining to be written, seeking a review for the current code so that new tests could be added.

Screenshot of the current passing tests:

image

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).

@theayushyadav11 theayushyadav11 requested a review from a team as a code owner January 29, 2025 20:42
@theayushyadav11
Copy link
Collaborator Author

Hi @adhiamboperes PTAL, as mentioned in the PR description these tests are not complete , once reviewed I would further add the remaining tests as EventLogSubject has the extensive scope.

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
EventLogSubject.kttesting/src/main/java/org/oppia/android/testing/logging/EventLogSubject.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
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 @theayushyadav11!

My main suggestion is to change how the tests are named to reflect classUnderTest_condition1BeingTested_condition2ifApplicable_expectedOutcome()

Please rename these tests before adding more so that you can get a good grasp of the pattern.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Please remove this file from test_file_exemptions.textproto so code coverage analysis can run.

@@ -70,8 +70,6 @@ import org.oppia.android.app.model.UserTypeAnswer
import org.oppia.android.app.model.WrittenTranslationLanguageSelection
import org.oppia.android.testing.logging.EventLogSubject.Companion.assertThat

// TODO(#4272): Add tests for this class.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please do a global search and remove any other occurrances of this TODO(#4272).

@RunWith(JUnit4::class)
class EventLogSubjectTest {
@Test
fun testHasTimeStamp_withTimeStamp_matchesTimeStamp() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

All the tests in this class needs to be renamed to follow our preferred format: https://github.com/oppia/oppia-android/wiki/Oppia-Android-Testing#guidelines-for-testing, e.g. testEventLogSubject_matchesCorrectTimestamp
testEventLogSubject_failsOnUnmatchingTimestamp

Comment on lines 28 to 37
@Test(expected = AssertionError::class)
fun testHasTimeStamp_withDifferentTimeStamp_fails() {
val eventLog = EventLog.newBuilder()
.setTimestamp(123456789)
.build()

EventLogSubject.assertThat(eventLog)
.hasTimestampThat()
.isEqualTo(987654321)
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

We don't use this pattern when testing. Prefer something likee:

Suggested change
@Test(expected = AssertionError::class)
fun testHasTimeStamp_withDifferentTimeStamp_fails() {
val eventLog = EventLog.newBuilder()
.setTimestamp(123456789)
.build()
EventLogSubject.assertThat(eventLog)
.hasTimestampThat()
.isEqualTo(987654321)
}
@Test
fun testEventLogSubject_failsOnUnmatchingTimestamp() {
val eventLog = EventLog.newBuilder()
.setTimestamp(123456789)
.build()
assertThrows<AssertionError>() {
EventLogSubject.assertThat(eventLog)
.hasTimestampThat()
.isEqualTo(987654321)
}
}

}

@Test(expected = AssertionError::class)
fun testIsEssentialPriority_withDifferentPriority_fails() {
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 testIsEssentialPriority_withDifferentPriority_fails() {
fun testEventLogSubject_matchEssentialPriorityWithDifferentPriority_fails() {

}

@Test
fun testHasNoProfileId_withNoProfileId() {
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 testHasNoProfileId_withNoProfileId() {
fun testEventLogSubject_eventWithNoProfileId_returnsNoProfileId() {

Ditto test below

Comment on lines 68 to 69
"//:dagger",
"//testing",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Are these two deps really required here?

@theayushyadav11
Copy link
Collaborator Author

Thanks @adhiamboperes for the review, I'll implement the changes as required.

@theayushyadav11 theayushyadav11 requested a review from a team as a code owner January 30, 2025 10:40
Copy link

Coverage Report

Results

Number of files assessed: 1
Overall Coverage: 8.06%
Coverage Analysis: FAIL

Failing coverage

File Coverage Lines Hit Status Min Required
EventLogSubject.kttesting/src/main/java/org/oppia/android/testing/logging/EventLogSubject.kt
8.06% 39 / 484 70%

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

@theayushyadav11
Copy link
Collaborator Author

Hi @adhiamboperes, PTAL! Let me know if I should continue writing tests for other methods or if you have any other suggestions. Thanks!

@oppiabot oppiabot bot assigned adhiamboperes and unassigned theayushyadav11 Jan 30, 2025
Copy link

oppiabot bot commented Jan 30, 2025

Unassigning @theayushyadav11 since a re-review was requested. @theayushyadav11, please make sure you have addressed all review comments. Thanks!

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.

Add tests for EventLogSubject
2 participants