1

I'm doing the "Android Basics in Kotlin" course from Google, and I'm in the testing and unit test part.

In the website, that uses the Android Studio version 2020, there is 2 folder that does no appear in my version(Chipmunk).

Link to the part I struggle with the Google course

Tried solutions like create manually the folders in src/test y en /src/test/java/, but in both the IDE warns me that the folders already exist.

Google pov My pov

How can I make them visibles like in the website to progress the course?

Apparently the folders create automatically when you start a project.

Thank you in advance.

Mijarax
  • 13
  • 3

1 Answers1

0

See first my screenshot screenshot to compare if folders really exist.

You can also go to your windows file explorer in your app folder diceroller/app/src/test/java/com/example/diceroller and see if ExampleUnitTest.kt is there. Maybe the last 3 folders which is the package folders might not exist.

Honestly i dont know if the package folders and the ExampleUnitTest.kt exist.

Firstly, to be able to create the package folders, create the directory folder, which will have inside, the package folders: screenshot2

then, double click on "java" folder to create: screenshot3

Of course do the same for the androidTest folder. Right click on androidTest folder -> New -> Directory. Then double click on "java". Just so you know, the androidTest is the instrumentation test folder and the test folder is the unit test folder.

To create the package folders, right click on "java"->new->package: screenshot4

then: screenshot5

and typing on com.example.diceroller and then enter. com example diceroller

If you want, I'll tell you for creating the ExampleUnitTest.kt too. Sorry if I don't know any button to show the folders and the tests. Anything you want ask me!

For creating the ExampleUnitTest.kt: Right click on your created "test" folder -> "New" -> "Kotlin Class/File".

Then name it by typing ExampleUnitTest and enter.

Copy paste this source code to your ExampleUnitTest file:

package com.example.diceroller

import org.junit.Test

import org.junit.Assert.*

/**
 * Example local unit test, which will execute on the development machine (host).
 *
 * See [testing documentation](http://d.android.com/tools/testing).
 */
class ExampleUnitTest {
    @Test
    fun addition_isCorrect() {
        assertEquals(4, 2 + 2)
    }
}

Do the same for creating instrumented test file but instead of right clicking on "test" folder, right click on "androidTest" folder -> "New" -> "Kotlin Class/File".

Then name it ExampleInstrumentedTest and enter.

After that copy paste this source code to your ExampleInstrumentedTest file:

package com.example.diceroller

import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4

import org.junit.Test
import org.junit.runner.RunWith

import org.junit.Assert.*

/**
 * Instrumented test, which will execute on an Android device.
 *
 * See [testing documentation](http://d.android.com/tools/testing).
 */
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
    @Test
    fun useAppContext() {
        // Context of the app under test.
        val appContext = InstrumentationRegistry.getInstrumentation().targetContext
        assertEquals("com.example.diceroller", appContext.packageName)
    }
}

If you want to save all that, go top left "File"-> "Save All". All good now? Anything you want, I'm here!

John Xenakis
  • 211
  • 2
  • 8
  • Sorry for the late response, I've been busy. I also was doing some experimentation and, indeed, this test folders do not exist in the project even though in the google course says that the packages or folder and the .kt file are created automatically. I will see if I can create both packages with the file and the coding inside. If you know hot to do it I will appreciate it. Thanks for the response. – Mijarax Dec 09 '22 at 02:36
  • @Mijarax Check my edit on how to create the files bro! – John Xenakis Dec 10 '22 at 19:20