Posts

Showing posts from April, 2022

Testing in Android

Image
Types of Testing : Unit Testing UI Testing Integration Test Unit Testing Used to test the business login of our application These tests are very fast and least expensive tests we can write because it runs on JVM The most commonly used tools for Unit testing are JUnit and Mockito Integration Testing Used to test the android components like Activity, Fragments, service, Context, Intent etc These run on JVM as well like the Unit Test and not on emulator or real devcie The most common tool for integration testing is Roboelectric UI Testing Used to test our User Interface like Views, Buttons, EditText, TextView etc These tests run on Emulator or Real Device The most common tool for UI testing is Espresso and UI Automator Suppose i create a class called Validation and create a method email() to check for the entered email pattern. class Validation { private val EMAIL_PATTERN = " [a-zA-Z0-9._-]+@[a-z]+ \\ .+[a-z]+ " fun email (email : String) : Boolean { return email...

Recyclerview steps

in the main activity, add recycler view activity_main.xml <? xml version ="1.0" encoding ="utf-8" ?> <androidx.constraintlayout.widget.ConstraintLayout xmlns: android ="http://schemas.android.com/apk/res/android" xmlns: app ="http://schemas.android.com/apk/res-auto" xmlns: tools ="http://schemas.android.com/tools" android :layout_width ="match_parent" android :layout_height ="match_parent" tools :context =".MainActivity" > <androidx.recyclerview.widget.RecyclerView android :layout_width ="match_parent" android :layout_height ="match_parent" android :id ="@+id/recyclerView" /> </androidx.constraintlayout.widget.ConstraintLayout> in the layout file, add a layout to add the items to display item_list, make the layout as MaterialCardView. Add linear layout and add the required stuffs with match parent, gravity...

Programs in Kotlin

Program to display the length of the string using higher order function by accepting String array and lambda expression as input fun main () { val data = listOf ( "Keshav" , "Pai" ) var result = IntArray(data. size ) val lambda : (List<String>) -> IntArray = { data -> for (i in 0 ..data. size - 1 ) { result[i] = data[i]. length } result } addTwoNumbers (data , lambda) } fun addTwoNumbers (stringList : List<String> , lambdaResult : (List<String>) -> IntArray) { var result = lambdaResult(stringList) for (i in result) { println (i) } } Program to add 2 numbers using higher order function and lambda expression fun main () { val lambdaResult : (Int , Int) -> Int = { x , y -> x + y} addTwoNumbers ( 3 , 8 , lambdaResult) addTwoNumbers ( 3 , 8 , { x : Int , y : Int -> x + y})     addTwoNumberss ( 3 , 8) { x : Int , y : Int -> x + y} } fun addTwo...