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

 

 

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s