diff --git a/README.md b/README.md index ee422e6..6e17b2d 100644 --- a/README.md +++ b/README.md @@ -110,14 +110,66 @@ It contains a way to setup responses to requests in a unified way. Contains all The actual server when running the application is [mockapi.io](https://www.mockapi.io/) so don't expect actual functionalities in the application. ## Code Kata -TODO -The kata will be in a separate branch with instructions and empty tests to be filled. +### Preperation +Download the project, open it in [Android Studio](https://developer.android.com/studio?gclid=Cj0KCQjw1PSDBhDbARIsAPeTqrfKrSx8qD_B9FegOmpVgxtPWFHhBHeqnml8n4ak-I5wPvqlwGdwrUQaAtobEALw_wcB&gclsrc=aw.ds). + +* In the gradle window you can see in the root gradle there is a "tests" group. In this group you will see a unitTests and androidTests task. +* First run the unitTests. +* When that finished, build the application to your phone. +* Login with whatever credentials and look over the app, what will you test. +* When finished, run androidTests. + +This will ensure the testing setup is proper, the project can resolve all the dependencies and such issues won't come up during your exercise. + +If everything is right, change branch to codeKata and look for into the [codekata](./codekata) folder for the instruction sets. + +### Structure + +The Code Kata is structured into 5 different section, each section in different what we are testing and how we are testing it. + +Since our layering is "app", "core" and "networking", of course we will jump right into the middle and start with core. + +#### Core +Open the [core instruction set](./codekata/core.instructionset). + +The core tests are the simplest, we will look into how to use mockito to mock class dependencies and write our first simple tests. + +Next we will look how to test flows. + +#### Networking +Open the [networking instruction set](./codekata/networking.instructionset). + +The networking instruction set will show you how to test network request with mockwebserver. + +It will also show you that you can write tests not only for one class mocking all the dependencies, but a component. + +#### App ViewModel Unit Tests +Open the [app viewModel unit tests instruction set](./codekata/viewmodel.instructionset). + +This section we will see how to replace the dispatcher to testDispatcher to control the ViewModel's coroutines. + +We will also see how to test with LiveData. + +We will introduce Rules, aka easy to reuse "Before" and "After" components. + +#### App Robolectric Unit Tests. +Open the [app storage unit tests instruction set](./codekata/storage.instructionset). + +In this section we will see how to test component depending on context such as Room database. + +#### Robolectric and Android Tests. +Open the [shared tests instruction set](./codekata/sharedtests.instructionset). + +In this tests we will see how to interact with View components in tests via Espresso. + +We will also see how to test a specific Activity (same concept can be applied to fragments) + +We will also see how can we share Robolectric test source with AndroidTests to run our same tests on actual device. ## Future Plans for Myself This just contains todos for myself when next time I am exercising testing on this project -- Finish Code Kata section, by adding new branch with empty tests and instructions - Add Room migration tests - Update RecyclerView tests with [Espresso.onData](https://developer.android.com/training/testing/espresso/lists) - Add [NavController](https://developer.android.com/reference/androidx/navigation/NavController) functionality and tests to it diff --git a/build.gradle b/build.gradle index f6cdc86..f688044 100644 --- a/build.gradle +++ b/build.gradle @@ -60,4 +60,14 @@ task clean(type: Delete) { delete rootProject.buildDir } +task unitTests(dependsOn: ["app:testDebugUnitTest", "core:test", "network:test"]){ + group = 'Tests' + description = 'Run all unit tests' +} + +task androidTests(dependsOn: "app:connectedAndroidTest"){ + group = 'Tests' + description = 'Run all Android tests' +} + apply from: 'gradlescripts/versions.gradle' \ No newline at end of file diff --git a/codekata/core.instructionset b/codekata/core.instructionset new file mode 100644 index 0000000..30404ce --- /dev/null +++ b/codekata/core.instructionset @@ -0,0 +1 @@ +TODO \ No newline at end of file diff --git a/codekata/networking.instructionset b/codekata/networking.instructionset new file mode 100644 index 0000000..30404ce --- /dev/null +++ b/codekata/networking.instructionset @@ -0,0 +1 @@ +TODO \ No newline at end of file diff --git a/codekata/sharedtests.instructionset b/codekata/sharedtests.instructionset new file mode 100644 index 0000000..30404ce --- /dev/null +++ b/codekata/sharedtests.instructionset @@ -0,0 +1 @@ +TODO \ No newline at end of file diff --git a/codekata/storage.instructionset b/codekata/storage.instructionset new file mode 100644 index 0000000..30404ce --- /dev/null +++ b/codekata/storage.instructionset @@ -0,0 +1 @@ +TODO \ No newline at end of file diff --git a/codekata/viewmodel.instructionset b/codekata/viewmodel.instructionset new file mode 100644 index 0000000..30404ce --- /dev/null +++ b/codekata/viewmodel.instructionset @@ -0,0 +1 @@ +TODO \ No newline at end of file