ScalaTest

ScalaTest is a testing tool in the Scala eco system. Using this, we can test Java and Scala code effectively. Its very easy to use and it follows Behavior Driven Development(BDD).

In this post, we are going to see the usage of ScalaTest with an example.

Refer the below Scala Object “Operation”. This object contains methods to perform various mathematical operation.

Operation

Now let’s write a test class with the ScalaTest tool. Refer below the list of steps to be done to write a test class.

1. Create a test class and extend FunSpec class.
2. Then use describe and it to structure the test class and write the necessary tests.

Refer below the sample test class to test all the methods of “Operation” object.

OperationSpec

When we run the above test, the Run screen will look like below,

RunScreen