Nicholas DiPinto
Nicholas DiPinto

Reputation: 307

Writing Unit Tests For TornadoFX

I have a Gradle project written in Kotlin using the TornadoFX framework. I am new to all of these things. Does anyone know, or can point me to, some tutorials on how to write unit tests for this type of project? I am not sure of TornadoFX is supposed to have its own testing framework, or if gradle has one that I should be using.

Upvotes: 2

Views: 543

Answers (1)

Nicholas DiPinto
Nicholas DiPinto

Reputation: 307

In case any people wander over to this page with the same question, here is the answer:

In my case, I used gradle to build this project. Therefore, I used gradle to run the tests. You write tests the same way you would in Java, like so

import org.junit.Test
import org.junit.Assert.*  //this imports your assert methods

class TestCases{

   @Test
   fun testMethod(){
      //initialize expected value
      //calculate actual value
      assertEquals(actual, expected)
   }
}

The important parts are the import statements and the '@Test' tag. The important statements give you the functionality to run tests. The '@Test' tag is put above any method that you want to be run as a test.

Once you finish writing your tests, go to your preferred terminal and cd to the directory containing your project. Then run this command (I work in Windows so I use a .bat file):

./gradlew.bat test

That's all you need to run unit tests for your Kotlin project.

Upvotes: 1

Related Questions