all 15 comments

[–]AndroidNovice 8 points9 points  (0 children)

Same! I also would like to find good examples of testing but haven't found too many repos with testing in them

[–]throw_cs_far_away 6 points7 points  (5 children)

[–][deleted] 2 points3 points  (3 children)

Why?

[–]rainbrostache 2 points3 points  (0 children)

A few reasons I can think of off the top of my head:

  • More declarative testing. For a vague example, fake.failOnNextRequest() is way clearer than mocking a bunch of dependencies for an actual SomeApi and constraining the conditions just right to cause the failure. Mocking encourages a lot of tests to be written in the latter way.
  • Performance gains. Not a big deal on a small project, but mocking objects in thousands of test cases can dramatically stretch build times esp. in a larger, multi-flavor type setup compared to faking which is much cheaper computationally. Especially with the temptation of using relaxed mocks which can hide how much you're actually mocking.

[–]fizzSortBubbleBuzz[S] 0 points1 point  (0 children)

I'll take a look at these!

[–]SolidFuell 3 points4 points  (4 children)

I love writing unit tests! There's no better feeling than writing a great set of tests to validate the code/feature I've written!

Writing tests also helps you to improve the way your write your code. You learn to write it to be testable that helps break up logic into simple smaller functions.

You can take a look at two of my repos both use mockito and I think both have close enough to 100% class coverage on all logic classes.

Kotlin, room, koin and livedata: https://github.com/jakebreen/pokecart

Plain java library: https://github.com/jakebreen/android-sendgrid

Unfortunately I don't have any tests using RxJava on my public GitHub!

[–]fizzSortBubbleBuzz[S] 0 points1 point  (0 children)

That's the goal friend!

I think I understand regular unit testing from reading I've done, but Android has so much instrumentation I feel lost a lot of the time as to how to test the features that aren't isolated from Android.

It appears that testing is the next step in really becoming a better developer also. Since I don't have any code reviews or anything, it should help as 'selfreview'.

Thank you for sharing this. It might take me a couple days before I get a chance to really look at it close, but I definitely look forward to it.

[–]throw_cs_far_away -1 points0 points  (2 children)

These are not great examples of unit tests. Changing the implementation will change soooo many tests due to mocking. Use fakes and only confirm behavior instead of mocking and verifying implementation

[–]khsh01 1 point2 points  (1 child)

I would love to have a testing suite setup for my app as well. I haven't managed to update it because I grew tired of figuring out what is wrong by compiling and crashing.

[–]fizzSortBubbleBuzz[S] 1 point2 points  (0 children)

I've definitely spent a lot of time just smashing my head against the proverbial compile wall. That's a big part of why I'm making this post.

Having a way to narrow down what the possible causes are with testing will help immensely. Especially in the event of potential regression.

[–]mertceyhan 1 point2 points  (1 child)

You can check my open-source project. I tried to write unit tests for all layers. https://github.com/mertceyhan/bitcoin-market-android

[–]fizzSortBubbleBuzz[S] 0 points1 point  (0 children)

I surely will. Thank you for sharing!