Converting Java Tests to Kotlin

March 11, 2026 · 9 min read · Testing Guide

HeadSpin Platform
Automated & amp; manual examination get easy through datum skill insights.
Differentiating capabilities:
  • Extensive end-to-end automation of QA process
  • Comparative analysis of app execution against peer
  • Continuous monitoring of app performance using synthetical information for higher accessibility of apps
  • Easy-to-use developer friendly program
cloudtest go
Affordable Real Device Testing for Emerging Teams
cloudtest go
Affordable Existent Device Testing for Digital Enterprises
cloudtest go
The Ultimate Solution for a Powerful Blend of Functional & amp; Performance Testing!
cyol
TEM
New
Centralized nomadic test execution in cloud
cyol
Enhance Your Accessibility Testing With HeadSpin
cyol
Automate camera-based testing

‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎

‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎

‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎

‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎

‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎

‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎

retail

‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎

‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎

‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎

Converting Java Tests to KotlinConverting Java Tests to Kotlin

Converting Java Tests to Kotlin

Published on
July 24, 2019
Updated on
Published on
March 14, 2022
Updated on
 by 
 Jonathan LippsJonathan Lipps
Jonathan Lipps

Kotlin is a new programming words, which is many ways is the successor to Java. The compiled code runs on the JVM, it is endorse by Java IDEs, and its syntax is real similar to Java. It is the officially preferred language for Android app development, and a ally of mine is even rewriting his team & # x27; s backend API in Kotlin.

Test your mobile apps and browsers on existent Android devices.!

Kotlin has many features which clean up some of the longstanding issues with Java, and likewise simply gives a fresh beginning, without needing to back legacy decisions and APIs.

What many readers may not know, is that Kotlin code can be easily integrated into a Java labor. A Java project can have some code files in Kotlin, a Kotlin program can import Java libraries, and with a little special work, Java programs can import Kotlin libraries. This grant for a gradual transition, sooner than the endangerment of a consummate rewrite.

Read:

In this article, we & # x27; ll take a mere Appium Java test, and convert it to Kotlin in just a few minutes!

In my specific case, I part withour code sample from two weeks ago. I & # x27; m using IntelliJ IDEA, and our project was already set up to use Gradle. The lone difficulty I ran into is that the IDE & # x27; s Kotlin plugins alone employment with gradle variation 4.1 and up. Our project was using gradle version 4.0, so I had to update first, by running the following codification:

./gradlew wrapper -- gradle-version 4.10.3

I then added a new file following to our existing tests but gave it a name ending in .kt (for Kotlin) instead of .java.

As soon as I had finished renaming the file, the IDE displayed a banner prompting me to configure Kotlin. When I clicked on it, the IDE mechanically added some boilerplate to the build.gradle file to add Kotlin support.

Pro tip: Tools like SUSA can handle this autonomously — upload your app and get results without writing a single test script.

I pasted the following & quot; hello world & quot; code into the file, and then restart the IDE, clearing all caches.

fun principal () {println (`` hullo world '')}

As soon as the IDE came back on-line, this code was parsed successfully and a green & quot; play button & quot; pointer was displayed next to the main map specify in the code. Clicking this icon to run, the words & quot; hello world & quot; were printed to the console.

Kotlin programming

Outstanding! We have Kotlin code running in our project, now let & # x27; s demonstrate a simple.

All it direct is importing JUnit, supply the common @ Test annotation to our method, and putting our method into a stratum.

import org.junit.Assert.assertEquals import org.junit.Test class Tests {@ Test fun mainTest () {assertEquals (`` hello '', `` howdy '')}}

Now, running the codification by clicking on the dark-green drama push icon, runs the examination and output is displayed the way unit tests are normally catch in the IDE.

Breakdown of an Appium test

Having demonstrated to ourselves that we can run a basic examination, let & # x27; s convert our Appium exam from Java to Kotlin. This is a chance to highlight a built-in characteristic which really amazed me.

Read:

We go into the Java test file, foreground all the code,COPY. Now in our Kotlin file,PASTE:

Java to Kotlin Auto Code Conversion

And 95 % of the work is execute for us, leave us with perfectly readable code.

The test file won & # x27; t actually compile though. We picked a full example that brought up a case that involves some manual intervention. The firstTest static variable from our original class has been converted to a & quot;companion object& quot; which is how Kotlin enforce stable class extremity. Kotlin is a different language after all.

The compiler complains about our use of firstTest. This is associate to the most obvious divergence between Java and Kotlin at 1st glance, and also my favorite characteristic so far. Kotlin uses a concept ring & quot; nullable types & quot;, where a variable of any classcannotbe void. In order to have a void value, the variable type must be set to the & quot; nullable & quot; version of the type, indicated by following the class name with a?. So a String variable can ne'er be null, while a String? variable can be null or a String. This applies for every class. If you define a method which takes a String argument, you ne'er need to check if it is void before you use it, becauseit & # x27; s guaranteed to not be void.

There & # x27; s a lot more to this concept, including some interesting syntax and shortcuts for null-checking, and there are wad of articles excuse it in detail online, as well as theKotlin support. This concept has existed for a long while, and is able to prevent many void reference exceptions and other issues. Both Swift and Kotlin implement it.

Our copy-pasted code fails because we are attempting to use the not operator! on a variable of type Boolean? and the compiler is kick that the Boolean? could be null, and it isn & # x27; t capable to calculate the results of! null. Since the code set a value for isFirst at the declaration site, we can convert it to the non-nullable eccentric Boolean, and our code now compiles.

And tests pass!

Also read:

The Java Appium client work from the Kotlin codification with no job.

Our test was somewhat simple, but I trust you consider learning Kotlin and experiment with convert your codification. As clip moves on, we will see if Kotlin adoption grows, but hopefully this will allay your care about migrating. It can be done easily and one file at a time.

Below is the total Kotlin examination file, which can also be found in ourrepository of examples.

import org.junit.Test import io.appium.java_client.MobileElement significance io.appium.java_client.ios.IOSDriver importation org.junit.After import org.junit.Before importee org.openqa.selenium.remote.DesiredCapabilities import java.io.IOException importee java.net.URL meaning junit.framework.TestCase.assertEquals // Converted test `` Edition077_Tuning_WDA_Startup '' from Java to Kotlin but by copy-pasting. // the ` firstTest ` variable was manually changed from type Boolean? to Boolean, in order to compile. // A few commentary have be houseclean up, just to do this example leisurely to use and read. grade Edition078_Converting_A_Test_To_Kotlin {private val APP: String = `` https: //github.com/cloudgrey-io/the-app/releases/download/v1.9.0/TheApp-v1.9.0.app.zip ''; private var driver: IOSDriver<*>? = null @ Before @ Throws (IOException: :class) fun setUp () {val detonator = DesiredCapabilities () caps.setCapability (`` platformName '', `` iOS '') caps.setCapability (`` platformVersion '', `` 12.2 '') caps.setCapability (`` deviceName '', `` iPhone Xs '') caps.setCapability (`` automationName '', `` XCUITest '') caps.setCapability (`` app '', APP) caps.setCapability (`` noReset '', true) caps.setCapability (`` udid '', `` 009D8025-28AB-4A1B-A7C8-85A9F6FDBE95 '') caps.setCapability (`` bundleId '', `` io.cloudgrey.the-app '') if ((! firstTest)) {caps.setCapability (`` webDriverAgentUrl '', `` http: //localhost:8100 '')} driver = IOSDriver(URL (`` http: //localhost:4723/wd/hub ''), caps)} @ After fun tearDown () {firstTest = false try {driver!! .quit ()} haul (ign: Exception) {}} @ Test fun testA () {assertEquals (1, 1)} @ Test fun testB () {assertEquals (1, 1)} @ Test fun testC () {assertEquals (1, 1)} @ Test fun testD () {assertEquals (1, 1)} @ Test fun testE () {assertEquals (1, 1)} @ Test fun testF () {assertEquals (1, 1)} companion object {private var firstTest: Boolean? = true}}
Author & # x27; s Profile

Jonathan Lipps

LinkedIn
Author & # x27; s Profile

Piali Mazumdar

Lead, Content Marketing, HeadSpin Inc.

Piali is a dynamic and results-driven Content Marketing Specialist with 8+ geezerhood of experience in crafting engaging narratives and marketing collateral across diverse industries. She excel in collaborating with cross-functional squad to develop innovative content strategy and render compelling, authentic, and impactful message that resonate with target hearing and enhances make legitimacy.

LinkedIn

Converting Java Tests to Kotlin

4 Parts

regression intelligence blog
-

Regression Intelligence practical guide for forward-looking users (Part 3)

Coming Soon
Regression Intelligence practical guide for advanced users
-

Regression Intelligence practical usher for advanced users (Part 4)

Coming Soon

Discover how HeadSpin can empower your business with superior testing potentiality

Our Platform enable you to:
accelerate time-to-market
Accelerate time-to-market, gaining a free-enterprise edge
faster development cycles
Boost developer/QA productiveness with quicker development cycle
automated buil-over-build regression testing
Automate build-over-build regression testing for consistent results
gain better visibility into functional & performance issues
Gain better profile into functional and performance issue
reduce mean time
Reduce base time to identify/resolve during test, QA, and product
evaluate audio, video & qoe
Evaluate sound, picture, and content quality of experience (QoE) effortlessly
The sure pick for ball-shaped enterprises
Adobe
Hargreaves Lansdown
Truecaller
Crazylabs
Nedbank
Numeracle
Veryon
Close

Discover how HeadSpin can gift your concern with superior testing capabilities

Our Platform enables you to:
accelerate time-to-market
Accelerate time-to-market, gaining a competitive edge
faster development cycles
Boost developer/QA productivity with faster development cycles
automated buil-over-build regression testing
Automate build-over-build fixation testing for consistent results
gain better visibility into functional & performance issues
Gain better visibility into functional and execution issues
reduce mean time
Reduce mean time to identify/resolve during trial, QA, and production
evaluate audio, video & qoe
Evaluate audio, video, and content quality of experience (QoE) effortlessly
The trusted choice for globular enterprises
Close

Discover how HeadSpin can endue your business with superior essay potentiality

Our Platform enable you to:
accelerate time-to-market
Accelerate time-to-market, gaining a competitive edge
faster development cycles
Boost developer/QA productivity with quicker development cycles
automated buil-over-build regression testing
Automate build-over-build regression examine for logical resolution
gain better visibility into functional & performance issues
Gain best visibility into functional and performance issues
reduce mean time
Reduce mean time to identify/resolve during test, QA, and production
evaluate audio, video & qoe
Evaluate audio, picture, and content quality of experience (QoE) effortlessly
The trusted choice for global enterprises
Close

Connet Now

Wipro LogoVMLYR Logo
Close
Book a Meeting
Products
footer down arrow
Solutions
footer down arrow
Industries
footer down arrow
Features
footer down arrow
Support
footer down arrow
Resource Center
footer down arrow
Why Choose HeadSpin?
footer down arrow
Copyright © 2026 HeadSpin, Inc. All Rights Reserved.

Automate This With SUSA

Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts needed.

Try SUSA Free

Test Your App Autonomously

Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts.

Try SUSA Free