Day37 of #100DaysOfCode

Kushagra Kesav
2 min readMar 15, 2022

--

#CodeTogether Day 37/100

Hii folks 🙌

Today I learned to write down some basic test cases in Kotlin and some intro to the debugging process.

Unit 1: Kotlin basics

Pathway 4: Add a button to an app

Source: https://developer.android.com/courses/android-basics-kotlin/course

Test Cases in Kotlin

  • First, open the app/build.gradle file and look at the dependencies. We will see some dependencies marked as testImplementation and androidTestImplementation, which correspond to unit and instrumentation tests. The code looks like this:

ExampleUnitTest.kt

@Test
fun generates_number() {
val dice = Dice(6)
val rollResult = dice.roll()
assertTrue("The value of rollResult was not between 1 and 6", rollResult in 1..6)
}

There are various indications that the test succeeded, namely green checks and the number of tests that passed.

Logging and debug output

  • Created a new project
  • In MainActivity.kt, before the class declaration, adding a constant called TAG, and set its value to the name of the class, MainActivity.
private const val TAG = "MainActivity"
  • Added a new function to the MainActivity class called logging() as shown.
fun logging() {
Log.v(TAG, "Hello, world!")
}
  • Called logging() in onCreate(). The new onCreate() method should look like the following.
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
logging()
}

That is all for Day37 ✅

Thanks for reading, See you tomorrow!

--

--