Skip to content

ashleyeatly/Unit-Testing-In-Scala

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Unit Testing in Scala

This project uses ScalaTest to write all the unit tests in the course.

Prerequisites

  • You must have git installed
  • You must have Java v13 installed
➜ java -version
openjdk version "13" 2019-09-17
OpenJDK Runtime Environment AdoptOpenJDK (build 13+33)
OpenJDK 64-Bit Server VM AdoptOpenJDK (build 13+33, mixed mode, sharing)
  • You must have sbt 1.3.3 or higher installed
➜ sbt --version
sbt version in this project: 1.3.3
sbt script version: 1.3.3
➜ scala --version
Scala code runner version 2.13.1 -- Copyright 2002-2019, LAMP/EPFL and Lightbend, Inc.

How to run?

  • Create a fork of this repo. Follow Github documentation on how to achieve this.
  • Clone your forked repo.
git clone https://github.com/<your-user-name>/Unit-Testing-In-Scala
cd Unit-Testing-In-Scala

Verify if the project is setup for the course

sbt "runMain BankOfScala"

Module 03 - Writing the First Test

Add the scalatest dependency in build.sbt

libraryDependencies += "org.scalatest" %% "scalatest" % "3.1.0" % "test"

Compiling & Running test using Scala

scalac -classpath "*.jar" HelloWorldSpec.scala
  • Run the Test
scala -classpath "*.jar" org.scalatest.run HelloWorldSpec

Module 07 - Mocking and Tagging Your Tests

The latest ScalaMock release 4.4.0 has not been updated with the latest ScalaTest release 3.1.0. There is an open pull request to merge the changes.

However, there are no breaking or conflicting changes between ScalaTest and ScalaMock. So, in order to learn ScalaMock, you can learn it with the ScalaTest release 3.0.8 which is 1 release behind the latest ScalaTest 3.1.0.

Clone the repository

https://github.com/hhimanshu/Unit-Testing-In-Scala-Mocking

The test source is available under src/test/scala.

To run all the tests, run

test

To run the test including a specific tag, run

testOnly -- -n com.h2.tags.Fast
testOnly -- -n com.h2.tags.Slow

To run the test excluding a specific tag, run

testOnly -- -l com.h2.tags.Fast
testOnly -- -l com.h2.tags.Slow

About

Learn to use ScalaTest in your own projects

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Scala 100.0%