From c91746439440600a698007824e6f3529c0efde9e Mon Sep 17 00:00:00 2001 From: mahmood199 Date: Tue, 27 Feb 2024 16:47:32 +0530 Subject: [PATCH] Learnt something new about paramterised test cases --- .../androidTest/AndroidTestingFilesHere.kt | 3 -- .../ExampleInstrumentedTest.kt | 2 +- .../TestDispatcherProvider.kt | 20 --------- .../main/java/com/example/audify/Sample.kt | 22 ++++++++++ .../utils => audify}/ExampleUnitTest.kt | 2 +- .../example/audify/ParameterizedSampleTest.kt | 36 ++++++++++++++++ .../java/com/example/audify/SampleTest.kt | 41 +++++++++++++++++++ .../WelcomeScreenScreenshotTest.kt | 2 +- 8 files changed, 102 insertions(+), 26 deletions(-) delete mode 100644 app/src/androidTest/AndroidTestingFilesHere.kt rename app/src/androidTest/java/com/example/{scrutinizing_the_service => audify}/ExampleInstrumentedTest.kt (97%) delete mode 100644 app/src/androidTest/java/com/example/scrutinizing_the_service/TestDispatcherProvider.kt create mode 100644 app/src/main/java/com/example/audify/Sample.kt rename app/src/test/java/com/example/{scrutinizing_the_service/utils => audify}/ExampleUnitTest.kt (86%) create mode 100644 app/src/test/java/com/example/audify/ParameterizedSampleTest.kt create mode 100644 app/src/test/java/com/example/audify/SampleTest.kt rename app/src/test/java/com/example/{scrutinizing_the_service/utils => audify}/WelcomeScreenScreenshotTest.kt (94%) diff --git a/app/src/androidTest/AndroidTestingFilesHere.kt b/app/src/androidTest/AndroidTestingFilesHere.kt deleted file mode 100644 index a40519a..0000000 --- a/app/src/androidTest/AndroidTestingFilesHere.kt +++ /dev/null @@ -1,3 +0,0 @@ - -class AndroidTestingFilesHere { -} \ No newline at end of file diff --git a/app/src/androidTest/java/com/example/scrutinizing_the_service/ExampleInstrumentedTest.kt b/app/src/androidTest/java/com/example/audify/ExampleInstrumentedTest.kt similarity index 97% rename from app/src/androidTest/java/com/example/scrutinizing_the_service/ExampleInstrumentedTest.kt rename to app/src/androidTest/java/com/example/audify/ExampleInstrumentedTest.kt index d1467e1..e4c9e02 100644 --- a/app/src/androidTest/java/com/example/scrutinizing_the_service/ExampleInstrumentedTest.kt +++ b/app/src/androidTest/java/com/example/audify/ExampleInstrumentedTest.kt @@ -1,4 +1,4 @@ -package com.example.scrutinizing_the_service +package com.example.audify /** * Instrumented test, which will execute on an Android device. diff --git a/app/src/androidTest/java/com/example/scrutinizing_the_service/TestDispatcherProvider.kt b/app/src/androidTest/java/com/example/scrutinizing_the_service/TestDispatcherProvider.kt deleted file mode 100644 index 7f03ff6..0000000 --- a/app/src/androidTest/java/com/example/scrutinizing_the_service/TestDispatcherProvider.kt +++ /dev/null @@ -1,20 +0,0 @@ -package com.example.scrutinizing_the_service - -import com.example.audify.v2.test_framework.DispatcherProvider -import kotlinx.coroutines.CoroutineDispatcher -import kotlinx.coroutines.Dispatchers - -class TestDispatcherProvider : DispatcherProvider { - - private val testDispatcher = Dispatchers.Unconfined - - override val main: CoroutineDispatcher - get() = testDispatcher - - override val io: CoroutineDispatcher - get() = testDispatcher - - override val default: CoroutineDispatcher - get() = testDispatcher - -} \ No newline at end of file diff --git a/app/src/main/java/com/example/audify/Sample.kt b/app/src/main/java/com/example/audify/Sample.kt new file mode 100644 index 0000000..deaeb24 --- /dev/null +++ b/app/src/main/java/com/example/audify/Sample.kt @@ -0,0 +1,22 @@ +package com.example.audify + +class Sample { + + + fun isPalindrome(input: String): Boolean { + var i = 0 + var j = input.length - 1 + var result = true + + while (i < j) { + if (input[i] != input[j]) { + result = false + break + } + + i++ + j-- + } + return result + } +} \ No newline at end of file diff --git a/app/src/test/java/com/example/scrutinizing_the_service/utils/ExampleUnitTest.kt b/app/src/test/java/com/example/audify/ExampleUnitTest.kt similarity index 86% rename from app/src/test/java/com/example/scrutinizing_the_service/utils/ExampleUnitTest.kt rename to app/src/test/java/com/example/audify/ExampleUnitTest.kt index d49110d..3129605 100644 --- a/app/src/test/java/com/example/scrutinizing_the_service/utils/ExampleUnitTest.kt +++ b/app/src/test/java/com/example/audify/ExampleUnitTest.kt @@ -1,4 +1,4 @@ -package com.example.scrutinizing_the_service.utils +package com.example.audify import org.junit.Test diff --git a/app/src/test/java/com/example/audify/ParameterizedSampleTest.kt b/app/src/test/java/com/example/audify/ParameterizedSampleTest.kt new file mode 100644 index 0000000..94c4449 --- /dev/null +++ b/app/src/test/java/com/example/audify/ParameterizedSampleTest.kt @@ -0,0 +1,36 @@ +package com.example.audify + +import org.junit.Assert.assertEquals +import org.junit.Test +import org.junit.runner.RunWith +import org.junit.runners.Parameterized +import org.junit.runners.Parameterized.Parameters + +@RunWith(value = Parameterized::class) +class ParameterizedSampleTest( + val input: String, + val expectedValue: Boolean +) { + + @Test + fun test() { + val sample = Sample() + val result = sample.isPalindrome(input = input) + assertEquals(result, expectedValue) + } + + companion object { + + @JvmStatic + @Parameters(name = "{index} : {0} is palindrome - {1}") + fun data(): List> { + return listOf( + arrayOf("Hellow", false), + arrayOf("level", true), + arrayOf("m", true), + arrayOf("", true), + ) + } + } + +} \ No newline at end of file diff --git a/app/src/test/java/com/example/audify/SampleTest.kt b/app/src/test/java/com/example/audify/SampleTest.kt new file mode 100644 index 0000000..403e81e --- /dev/null +++ b/app/src/test/java/com/example/audify/SampleTest.kt @@ -0,0 +1,41 @@ +package com.example.audify + +import org.junit.After +import org.junit.Assert +import org.junit.Before +import org.junit.Test + + +class SampleTest { + + lateinit var sample: Sample + + @Before + fun setup() { + sample = Sample() + } + + @Test + fun isPalindrome_input_hello_expect_false() { + // Arrange + // Act + val result = sample.isPalindrome("Hello") + // Assert + Assert.assertEquals(false, result) + } + + @Test + fun isPalindrome_input_level_expect_true() { + // Arrange + // Act + val result = sample.isPalindrome("level") + // Assert + Assert.assertEquals(true, result) + } + + @After + fun tearDown() { + println("After running the test") + } + +} \ No newline at end of file diff --git a/app/src/test/java/com/example/scrutinizing_the_service/utils/WelcomeScreenScreenshotTest.kt b/app/src/test/java/com/example/audify/WelcomeScreenScreenshotTest.kt similarity index 94% rename from app/src/test/java/com/example/scrutinizing_the_service/utils/WelcomeScreenScreenshotTest.kt rename to app/src/test/java/com/example/audify/WelcomeScreenScreenshotTest.kt index a048d9c..325fa63 100644 --- a/app/src/test/java/com/example/scrutinizing_the_service/utils/WelcomeScreenScreenshotTest.kt +++ b/app/src/test/java/com/example/audify/WelcomeScreenScreenshotTest.kt @@ -1,4 +1,4 @@ -package com.example.scrutinizing_the_service.utils +package com.example.audify import app.cash.paparazzi.DeviceConfig import app.cash.paparazzi.Paparazzi