Test coverage for Kotlin Multiplatform project(KMM) - android

I have one project(android and iOS) where I am sharing the common code inside shared folder. I have written both unit tests under commonTest(unit-test) folder as well as Instrumentation test inside androidTest(instrumentation test) folder. It works well when I run individual test. But I want to see the coverage also. While I can do this "run with test coverage" for commonTest but it's not available for androidTest. Any tool that will be helpful here. I tried searching and tried few stuffs with jacoco and kover but could not help.

Related

How to do Unit testing in Android Studio?

I am a Beginner in Android. I want to write a unit testing code in Android studio. How to run that testing in real device and also how to get the test result. I can able to see AndroidTest folder in src folder.
It is a good practice to write Unit Test code from scratch. But if you have learned a little bit of Unit testing basic you can take advantage of IntelliJ plugins for Android Studio to generate Unit Testing code very easily.
Try this:
TestMe(https://plugins.jetbrains.com/plugin/9471-testme)
Auto Generate Unit Tests for source class in Java or Groovy.
No more boilerplate!
Features:
Auto-generate Java or Groovy test code with JUnit 4/5, TestNG or Spock frameworks
Auto-generate Mockito mocks
Generate test params and assertion statements
Quick-Start:
http://weirddev.com/testme/

What is the use of test directory in android studio?

I have been using android studio for some time.(still learning) and till date i haven't used the java files in the test folders. i.e the one's marked here :-
Is it necessary for a project or can we just delete those files?
If it is necessary, what is its use and how can we use it ? (any reference would be great).
If anyone could rephrase the question in a better way,it would be better.
Those are for tests. The androidTest is for instrumented tests while the test folder is for unit tests. You could delete them if you do not plan on using it, but it also does not harm your project.
See here Test Your App

Run Unit Test Before Launch

I have just created my first unit test as part of an android project. I followed the guide found here.
Now I would like to include all unit tests in the "test" package before the app is launched to the phone. How would I include this in the gradle file?

How to exclude a test from a test application using eclipse android-junit launch configuration

I got an application project under test and a test application project (on Android).
My test app contains a lot of tests but I would like to find a mechanism to exclude a test, or a test class from the test launch (launched from eclipse).
I know I can exclude tests on the command line based on annotations for instance, or use ant to exclude classes, but I don't have this kind of configuration and want to exclude them directly from eclipse).
Is it possible to exclude a test, or a bunch of tests from a from a test application using eclipse android-junit launch configuration ?
Thanks in advance !
Android JUnit Test launch configuration is lack of functionality which only support configure running either all tests or single one test class at the moment.
Alternatively, instead of trying to include/exclude tests right before junit run time, we can include/exclude specific test source files at project build time by configuring project build path in Eclipse, right-click your test project, go to Build Path -- Configure Build Path, in the Source tab, edit Excluded section and add multiple test source files, this will exclude the test source files from your project build path and finally exclude them when you start running Android JUnit test:
DISCLAIMER: This answer is for normal JUnit 5 Test configurations, and is not Android specific. But since this was the first result I got for a more generic Google search, I figured I'd update here for whom it may benefit.
As of Eclipse Oxygen (4.7.3a), I am able to create a new JUnit Run Configuration and add Tags to include/exclude during a test run. Classes (and I believe methods too) can be decorated with the #Tag("") annotation and the test runner will filter those out. I am using JUnit 5 with a relatively straight-forward Java application using the Spring Framework.
Run > Run Configurations... > JUnit > New > Configure...
I have a package src/test/java, with a test class called JoinConfigIT, with an annotation at the top of my classed of #Tag("integration").
Now when I run the IntegrationTests run configuration that I created, it only runs all tests with classes decorated with the #Tag("integration") annotation.
I hope this helps someone. Good luck.
You can use annotations #SmallTest, #MediumTest or #LargeTest and create different configurations for launching different tests. See this docs.
I think testSuite class would do the trick. It is designed to help organize tests.
Please reference sample code in apiDemos test and read corresponding doc. Best of luck.

Trying to understand android testing

I'm a long time Java developer with many years of Java EE, Ant, Maven, unit testing, mocks, etc. I'm currently using gradle to build android apps and am looking at unit testing them. And it's got me tearing my hair out!
My reading indicates that to test an app, I have to create another app inside it in a test directory. But I'm not sure how this embedded app can see the main apps classes. I presume that google came up with this because of something to do with the manifests which are different. I'm not sure why.
Without doing this embedded app system, I've been able to get unit tests to run by including the test classes with the main classes in the APK, adding the instrumentation declarations to the manifest, deploying it and running the test runners. But I don't want to be compiling test classes with app classes and including all the dependencies so that's not really an option and I'm not really sure of the effects of the changes to the manifest as I cannot find any documentation about the effects.
None of this is understood by gradle which follows the maven system of building. Also note that the android way seems to be that the embedded sub-project (test) is dependant on the main parent project, something that is totally contray to gradle and maven.
Another option seems to be separate the test project so that it's completely outside the app project. But really, I'd like to use a similar convention to maven and simply have tests in a separate directory, along with the manifest in test resources.
Has anyone managed to get testing on the emulators running unit tests following a more maven like directory structure?
You can try Robotium. It provides lots of features for a better testcase. You can have a look at it here.
Do you have to run the unit tests in the emulator? Isn't that too slow? I've been using robolectric ( http://pivotal.github.com/robolectric/ ) which creates shadow objects that work similar to mocks. I use progaurd ( http://proguard.sourceforge.net/ ) to strip out the tests for the release build.

Categories

Resources