https://kotlinlang.org logo
Join SlackCommunities
Powered by
# testing
  • s

    sendoav

    03/29/2021, 2:55 PM
    Hi All, after upgrading build gradle tools from 4.0.2 to 4.1.0 my jacoco coverage reports state zero percentage of coverage, anyone experiencing the same issue? I'm using jacoco plugin 0.8.6
    🙋‍♂️ 1
    m
    • 2
    • 1
  • a

    amadeu01

    05/05/2021, 5:14 PM
    hey ppl, I'm looking at the kotlin repo (https://github.com/JetBrains/kotlin) to look up good approaches for writing tests. However, I'm a bit overwhelming by the amount of tests. So, I would like to ask if you know some good files to have as an example to be followed
  • c

    Colton Idle

    05/14/2021, 2:41 AM
    I'm using Android Studio, but I'm working in a plain old java/kotlin lib/module I have this test that runs correctly
    Copy code
    @Test
        fun `one plus one`() {
            val result = 1 + 1
            assertThat(result).isEqualTo(2)
        }
    but when I add
    Copy code
    @BeforeClass
        fun setup() {
    
        }
    Then I get an error rerunning the test. "No tests found for given includes:" Ideas? I've looked on stackoverflow and it seems that having the tests run with intellij vs gradle could be the culprit but my test does actually run successfully without the setup step added and so I'm hard pressed as to why adding that simple block would be making things act strange. Edit: Figured it out. Needed @BeforeClass @JvmStatic and put that method in a companion object.
  • c

    Chris Jobling

    05/21/2021, 3:38 PM
    Good Morning / Good Afternoon. We are looking to do end-to-end testing for our Kotlin microservices. We have previously used https://cucumber.io/docs/installation/kotlin/ and i am wondering if anyone has used any different tools/tech which could be of advantage to us. Thanks
    m
    • 2
    • 1
  • n

    Nikolay Kasyanov

    05/28/2021, 7:57 AM
    Hey folks, is there a way to make
    org.junit...
    not importable in tests of multiplatform project? For context, I only have
    kotlin('test')
    and
    kotlin('test-annotations-common')
    in
    commonTest
    and
    kotlin('test-junit')
    in
    jvmTest
    . No direct dependency to JUnit whatsoever, but it’s still importable because it’s still in the classpath I guess?
    👍 1
  • b

    Byron Katz

    05/30/2021, 2:34 PM
    I'd like to hear if anyone has a take on this as well. Because Gradle brings in a bunch of dependencies, Intellij suggests to use tools I haven't explicitly intended.
  • n

    napperley

    08/18/2021, 2:11 AM
    Are there alternative ways to test a Kotlin Native library (like Com Bot SSH for example - https://gitlab.com/com-bot/combot-ssh ) in the same project without having to rely on Unit testing? What I want to do is develop a test program (to do manual library testing) in the same project where the Kotlin library resides, that can test some things which Unit testing doesn't cover (eg networking).
  • t

    Tobi M.

    11/24/2021, 9:12 AM
    Which library are you using for snapshot testing in Kotlin, if any? 🙂
    p
    • 2
    • 3
  • a

    andylamax

    12/01/2021, 4:17 AM
    Cross posting here https://kotlinlang.slack.com/archives/C0B8L3U69/p1638332223084600 because I think it is relevant to this channel as well
  • c

    Colton Idle

    02/04/2022, 2:30 PM
    I have a plain old little java library with about 20 unit tests, but now I want to just change one variable for the tests so that I have 40 tests (its the same 20 tests, ran twice, with different inputs). How can you do that with kotlin + gradle?
    a
    m
    • 3
    • 8
  • c

    Colton Idle

    02/07/2022, 9:42 PM
    Running tests stopped showing results in the test result pane. All I get now is the gradle run pane. Any way to get it back? (edited) i.e. this pane is missing when running my tests. I tried invalidate/restart with no luck
    m
    • 2
    • 1
  • b

    Brian Donovan

    02/13/2022, 4:23 PM
    hey everyone, can I get some guidance on why this test is not failing? Thanks
    Copy code
    @RunWith(AndroidJUnit4::class)
    class LoginTest {
    
        @get:Rule
        val composeTestRule = createAndroidComposeRule<MainActivity>()
    
        @Test
        fun logInButtonEnabledTest() {
    
            composeTestRule.setContent {
                WHApplicationTheme {
                    LoginScreen({}, {}, {})
                }
            }
    
            val email = "sampl"
            val password = "Sa"
    
            val isValidEmail: Boolean = EmailValidator.isValid(email)
            val isValidPassword: Boolean = PasswordValidator.isValid(password)
    
            if (isValidEmail && isValidPassword) {
                composeTestRule
                    .onNodeWithTag(EMAIL_TEXT_FIELD)
                    .performTextInput(email)
                composeTestRule
                    .onNodeWithTag(PASSWORD_TEXT_FIELD)
                    .performTextInput(password)
            }
    
            composeTestRule
                .onNodeWithTag(LOG_IN_BUTTON)
                .performClick()
        }
    }
    
    
    interface FormValidator {
        fun isValid(value: String): Boolean
    }
    
    
    object PasswordValidator : FormValidator {
    
        override fun isValid(value: String): Boolean {
            return value.length > 5 && !value.contains(" ")
        }
    }
    
    
    object EmailValidator : FormValidator {
    
        override fun isValid(value: String): Boolean {
            val emailCheck = "^[A-Za-z](.*)([@])(.+)(\\.)(.+)"
            return emailCheck.toRegex().matches(value)
        }
    }
  • a

    andylamax

    02/20/2022, 1:22 AM
    Cross Positing here just because I think it is relevant https://kotlinlang.slack.com/archives/C0B8L3U69/p1645320100575809?thread_ts=1645138502.823009&amp;cid=C0B8L3U69
  • b

    Big Chungus

    06/22/2022, 8:20 PM
    klip@0.4.1 is out with the reworked persistence strategy that now works on the browser tests too! Give it a go if you've already upgraded to kotlin 1.7.0. WTH is klip you might ask? Well it's a test snapshot library for the entirety of KMP powered by a tiny kotlin compiler plugin. In short it lets you assert current state of your test output data vs some previously frozen version of it to ensure consistency and no changes. If you're familiar with jest snapshot testing - it's exactly that but for KMP. Slack Conversation
  • o

    oianmol

    10/28/2022, 7:05 AM
    Hi 👋 folks! How do you create a test suite for kotlin common tests ?
  • l

    Landry Norris

    11/17/2022, 3:07 PM
    Is there anything built in to check if a String matches a regex? I know I could assertTrue with a Regex, but I’d like the output to give me the failing string and the regex if it fails.
  • t

    teddy

    12/02/2022, 12:29 AM
    Anyone has any idea to write a unit test for this ViewModel file? I appreciate if you can give me an example code or any keyword for me to search the issue? Thank you very much
    a
    • 2
    • 1
  • n

    Narayan Iyer

    12/14/2022, 1:02 PM
    Hello friends, is there a test automation framework in Kotlin like Cypress (http://cypress.io)?
    b
    • 2
    • 1
  • b

    Big Chungus

    02/20/2023, 10:00 AM
    Has anyone figured out how to write dynamic tests on native? I'm fine with using undocumented/unstable/internal APIs if that helps.
  • b

    Blaž Vantur

    04/11/2023, 9:33 AM
    Does anyone have a good open-sourced example project where StateFlow is covered with unit tests? Ideally with Turbine library.
  • a

    andylamax

    08/08/2023, 12:11 AM
    https://kotlinlang.slack.com/archives/C3PQML5NU/p1691403871904099
  • g

    galvas

    08/23/2023, 2:53 PM
    Hey folks, I'm trying o write a fake implementation of a sealed interface on my unit tests. But I get an
    Inheritance of sealed classes or interfaces from different module is prohibited
    error. I assumed that the tests source would be part of the same module as the production code. Am I missing something? Any tips?
  • a

    Anmol Verma

    10/01/2023, 4:00 AM
    https://medium.com/@oianmol/custom-test-lab-for-android-cd74a2a9df6f
  • d

    Darryl Pierce

    11/27/2023, 7:55 PM
    Hi, all. I"m looking for any information on using mock objects when writing tests for Kotlin multiplatform apps. Any recommendations would be appreciated.
    x
    • 2
    • 3
  • j

    Jonathan

    12/14/2023, 4:44 PM
    Hey! I’m working on adding a robust baseline profile to my Wear OS app. I’m running into a strange issue where sometimes
    device.findObject(By.res(…))
    returns null. I can see all queried elements are on screen. I haven’t seen any documentation mentioning that this methods behaves in a best effort fashion. Has anyone experienced this before or know why this happens? I’ve not been able to determine a rhyme or reason for this behavior. Here, is an excerpt from my StartupBaselineProfile that’s through an exception:
    Copy code
    device.findObject(By.res(UiTestingTags.HMOBatterView)).also { batterView ->
        device.wait(Until.hasObject(By.res(UiTestingTags.HMOBatterViewBalls)), 10_000)
        // Increment the number of balls until the "walk" dialog displays.
        batterView.findObject(By.res(UiTestingTags.HMOBatterViewBalls)).also { ballsButton ->
            ...
        }
    }
    Specifically the NPE happens:
    batterView.findObject(By.res(UiTestingTags.HMOBatterViewBalls))
    I performed a clean and rebuild and the code ran without exception. I’m not sure if this is a factor in the matter but I’m testing on a WearOS emulator (Wear OS Large Round API 33)
  • l

    Levi

    12/20/2023, 6:13 PM
    General question on organizing tests: do folks tend to (or is there a convention to) structure the directories and packages in
    src/test
    to match
    src/main
    ?
    a
    b
    • 3
    • 4
  • b

    Big Chungus

    12/28/2023, 3:01 PM
    Does anyone know why kotlin-test is not being published with gradle metadata and instead requires adding kotlin-test-common, kotlin-test-js, and kotlin-test-annotations separately?
    👀 1
    m
    • 2
    • 11
  • j

    Jonathan

    01/03/2024, 9:59 PM
    Following up on this message, because I’m running into issue while generating baseline profiles. Does anyone know under what circumstances
    UiDevice.findObject()
    will return
    null
    ?
  • a

    Alina Dolgikh [JB]

    07/03/2024, 12:50 PM
    Hi <!here>, Since we have the #test channel, which is older and more populated, can I delete this one? If there is a reason for having both channels, please let me know, and I’ll help rearrange them in a way that won’t confuse the community.
    👍 4
    👍🏾 1
  • a

    Alina Dolgikh [JB]

    07/09/2024, 9:26 AM
    archived the channel