Skip to content

Brown5cj code review2#17

Open
ccbrowndev wants to merge 5 commits intomainfrom
brown5cj_CodeReview2
Open

Brown5cj code review2#17
ccbrowndev wants to merge 5 commits intomainfrom
brown5cj_CodeReview2

Conversation

@ccbrowndev
Copy link
Copy Markdown
Collaborator

Analysis of the App

This app is a social media app where college students can join a community of users at the university, get news for the school, and join groups for things like sports teams or clubs. The app builds and runs fine. So far the UI appears to have fields for adding posts and the ability to log in, so multiple core functionalities have already been implemented.

Code Availability and Buildability

The code was available on GitHub on time, builds and runs.

Documentation

The documentation is enough that I have a general idea what is going on and what they plan to do in the future. I can also figure out specifics fairly quickly by just using context.

3 Things I learned

  1. Learned about implementing let statements in tests to avoid using force unwrap
  2. Learned about logging errors by using Log.e
  3. Learned some about mocking although I could not get it to work, so I made sure changes that would cause tests to fail were reverted
    • Honestly a little bit confused about testing and the whole mocking thing. It seems like mocking is more to test individual services or dependencies rather than a dto?

Changes I made

  1. Make university testing its own file and removed unused code related to services
  2. Make post testing its own file
  3. Move university integration testing to its own file and added a test to ensure the list of universities was not empty

Rationale for Changes

These changes make the tests into their own separate files so it's easier to work with and less confusing to read. I also add some test coverage by ensuring retrofit parses actual university objects instead of an array of empty strings. It did properly parse though so looking good!

3 Commits from my own group project

  1. Implementing a custom JSON deserializer to place ingredients into a map
  2. Implementing MVVM with Live Data
  3. Laying the groundwork for Koin

import org.junit.Assert
import org.junit.Test

class PostUnitTest {
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Having Post DTO use its own file prevents testing from getting cluttered into a single file

Comment on lines -35 to -47
@get:Rule
var rule: TestRule = InstantTaskExecutorRule()

lateinit var mvm : MainViewModel

private val mainThreadSurrogate = newSingleThreadContext("Main thread")

@MockK
lateinit var mockUniService : UniversityService


lateinit var universityService: IUniversityService
var allUniversities : List<University>? = ArrayList<University>()
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

none of these things were actually being used, leaving a lot of code sitting around, not contributing

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Are you certain they are not being used?
It looks like a valid unit test to me.

Comment on lines +52 to +56
private fun thenTheUniversityCollectionShouldContainMarywoodUniversity() {
Assert.assertNotNull(allUniversities)
allUniversities?.let {
Assert.assertTrue(it.isNotEmpty())
var containsMarywoodUniversity = false
Copy link
Copy Markdown
Collaborator Author

@ccbrowndev ccbrowndev Apr 5, 2022

Choose a reason for hiding this comment

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

Test to ensure not only that the collection is not empty but that the contents of items in the collection are not empty

Use let to avoid a forced unwrap situation

}
}
Assert.assertTrue(containsMarywoodUniversity)
} ?: Log.e(TAG, "allUniversities was null")
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Using Log.e here to print to the logs in the instance that allUniversities is somehow null. This shouldn't happen because we already did a test for that, but as part of implementing the let statement, I believe something is needed in the case that it somehow is null, so I included this

Comment on lines -45 to +47
/*allPosts.add(Post(NEW_SPECIMEN))*/
/*allPosts.add(Post(NEW_SPECIMEN))*/
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

As long as you're here, remove this entirely.
Avoid pushing commented code to Version Control. Version control has tools that makes this unnecessary.

  • You can look at history to see what used to be there.
  • You can use branches for experimental features.

@discospiff
Copy link
Copy Markdown

From this review:

  • The IDE can format code automatically, and consistently, for all developers on the team. I'd use this instead of creating a branch, formatting manually, and then merging the branch.
  • I'm not quite clear on the changes to the unit tests. Were some tests removed? Moved? Added?
    Bottom line, I don't have a good handle on the technical debt reduction in this review... at least, not enough to recommend a merge.

@ccbrowndev
Copy link
Copy Markdown
Collaborator Author

From this review:

  • The IDE can format code automatically, and consistently, for all developers on the team. I'd use this instead of creating a branch, formatting manually, and then merging the branch.
  • I'm not quite clear on the changes to the unit tests. Were some tests removed? Moved? Added?
    Bottom line, I don't have a good handle on the technical debt reduction in this review... at least, not enough to recommend a merge.

I should have not committed the formatting part, it was done by the IDE and I simply forgot about those changes and committed it. The main things I did were separating tests into 3 files:
1 for unit testing university dto
1 for unit testing post dto
1 for integration testing to make sure the API is working and pulling data

Previously tests for all 3 of these things were housed in a single file which was a little bit hard to read

I also replaced forced unwraps in the integration testing file with let statements and added an additional test

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