SlideShare a Scribd company logo
Scala Test

Meetu Maltiar - mmaltiar@inphina.com
Introduction
Introduction Continued ..

With ScalaTest, we can test either Scala or Java
code.

Integrates with popular tools such as JUnit,
TestNG, Ant, and Maven

Designed to do different styles of testing like
Behavior Driven Design for example
Simple Junit4 Test
package com.inphina.ibat.junit

import org.scalatest.junit.AssertionsForJUnit
import org.junit.Assert._
import org.junit.Test
import org.junit.Before


class SimpleJunit4Demo extends AssertionsForJUnit {

    var sb: StringBuilder = _

    @Before def initialize() {
      sb = new StringBuilder("ScalaTest is ")
    }

    @Test
    def verifyEasy() {
      sb.append("easy!")
      assertEquals("ScalaTest is easy!", sb.toString)
    }

}
Concepts

Three concepts:
●
    Suite: A collection of tests. A test is anything which has a name
and can succeed or fail.

●
    Runner: ScalaTest provides a Runner application that can run
Suites of tests

●
    Reporter: As the tests are run, events are fired to a reporter, it
takes care of presenting results back to the user
Scala Test Is Customizable

                              Suite
                             <<trait>>

  def expectedTestCount(Filter): Int
  def testNames: Set[String]
  def tags: Map[String, Set[String]]
  def nestedSuites: List[Suite]
  def run(Option[String], Reporter, ...)
  def runNestedSuites(Reporter, ...)
  def runTests(Option[String], Reporter, ...)
  def runTest(Reporter, ...)
  def withFixture(NoArgTest)
Under The Hood
When you run a Test in Scala Test you basically invoke
run(Option[String], Reporter, .. ) on Suite Object.
●
  It then calls runNestedSuites(Reporter, ..)
●
  And it calls runTests(Option[String], Reporter, ..)

runNestedSuites(Reporter, ..) :
●
  invokes nestedSuites() : List[Suite] to get a List of nested Suites

runTests(Option[String], Reporter, ..) will call def testNames:
Set[String] to get a Set of test names it needs to run. For each test
name it calls runTest(Reporter, ...) It wraps the test code as a
Function Object with a name and passes it to withFixture(NoArgTest)
which actually runs the test.
Pick a Core Trait
Mix In Other Traits
Traits in Scala Test
•
  Suite
•
  Funsuite
•
  Spec
•
  FlatSpec
•
  WordSpec
•
  FeatureSpec
•
  Assertions
•
  ShouldMatchers
•
  MustMatchers
Suite
➢
  Traits approach to writing tests. Simply create
classes extending Suite and define test methods.
➢
 Test methods have names testXXXX. All methods
must be public.
➢
 Scala Test provides === operator. It is defined in
Traits Assertions. Allows the failure report to include
both right and left values.
Suite Demo
FunSuite
➢
 For writing Functional Tests use FunSuite Fun =>
Functional Suite.
➢
 "test" is a method defined in FunSuite Trait. Test name
goes in parentheses and the test code goes in curly
braces.
➢
 The test code in curly braces is passed as a by-name
parameter to "test" method which registers for later
execution
➢
 A FunSuite's life-cycle has two phases: the registration
phase and the ready phase.
FunSuite Demo
Spec

➢
  Trait that facilitates a “behavior-driven” style of
development (BDD), in which tests are combined with text
that specifies the behavior the tests verify.
➢
 A Spec contains describe clauses and tests. We define
a describe clause with describe, and a test with it. Both
describe and it are methods, defined in Spec, which will
be invoked by the primary constructor of StackSpec.
Spec Demo
FeatureSpec
➢
 A suite of tests in which each test represents one
scenario of a feature.
➢
  FeatureSpec is intended for writing tests that are "higher
level" than unit tests, for example, integration tests,
functional tests, and acceptance tests.
➢
 A FeatureSpec contains feature clauses and scenarios.
we define a feature clause with “feature”, and a scenario
with “scenario”. Both feature and scenario are methods,
defined in FeatureSpec
FeatureSpec Demo
Summary


Scala Test is a low risk way to get started
➢


with Scala
➢
 Scala Test shows what Scala can
leverage for our projects
References

➢
 Bill Venners presentation “Get Higher
With Scala Test”
➢
    Scala Test website www.scalatest.org

More Related Content

What's hot (20)

PDF
Introduction to HTML
Professional Guru
 
PPTX
Css types internal, external and inline (1)
Webtech Learning
 
PPTX
CSS Animations & Transitions
Edward Meehan
 
PDF
Dynamic CSS: Transforms, Transitions, and Animation Basics
Beth Soderberg
 
PDF
Android Modularization
Young-Hyuk Yoo
 
PPTX
Introduction to JSX
Micah Wood
 
PPTX
Css
Hemant Saini
 
PPTX
Css position
Webtech Learning
 
PPT
Html ppt
Iblesoft
 
PPTX
Introduction to HTML+CSS+Javascript.pptx
KADAMBARIPUROHIT
 
PPTX
Its time to React.js
Ritesh Mehrotra
 
PPTX
Json
Steve Fort
 
PPT
Unit testing with java
Dinuka Malalanayake
 
PPT
android layouts
Deepa Rani
 
PPTX
Html links
JayjZens
 
PPTX
Web development using html and wordpress
Dakshata Gavand
 
PPTX
Java script
Sadeek Mohammed
 
PPTX
HTML Fundamentals
BG Java EE Course
 
PDF
3.2 javascript regex
Jalpesh Vasa
 
PPT
Control Structure in C
Neel Shah
 
Introduction to HTML
Professional Guru
 
Css types internal, external and inline (1)
Webtech Learning
 
CSS Animations & Transitions
Edward Meehan
 
Dynamic CSS: Transforms, Transitions, and Animation Basics
Beth Soderberg
 
Android Modularization
Young-Hyuk Yoo
 
Introduction to JSX
Micah Wood
 
Css position
Webtech Learning
 
Html ppt
Iblesoft
 
Introduction to HTML+CSS+Javascript.pptx
KADAMBARIPUROHIT
 
Its time to React.js
Ritesh Mehrotra
 
Unit testing with java
Dinuka Malalanayake
 
android layouts
Deepa Rani
 
Html links
JayjZens
 
Web development using html and wordpress
Dakshata Gavand
 
Java script
Sadeek Mohammed
 
HTML Fundamentals
BG Java EE Course
 
3.2 javascript regex
Jalpesh Vasa
 
Control Structure in C
Neel Shah
 

Viewers also liked (17)

PDF
Metaprogramming in Scala 2.10, Eugene Burmako,
Vasil Remeniuk
 
KEY
Scalding: Twitter's Scala DSL for Hadoop/Cascading
johnynek
 
PPTX
Scala in practice
Tomer Gabel
 
PDF
Scala profiling
Filippo Pacifici
 
PPT
Scala Talk at FOSDEM 2009
Martin Odersky
 
PDF
Procedure Typing for Scala
akuklev
 
PDF
BigData, Hadoop과 Node.js, R2
고포릿 default
 
PDF
RESTful Java
JavaCommunity.Org
 
PPTX
Elixirと他言語の比較的紹介 ver.2
Tsunenori Oohara
 
PDF
Go言語によるwebアプリの作り方
Yasutaka Kawamoto
 
PDF
PHP7はなぜ速いのか
Yoshio Hanawa
 
PDF
java 8 람다식 소개와 의미 고찰
Sungchul Park
 
PPTX
地獄のElixir(目黒スタートアップ勉強会)
Tsunenori Oohara
 
PDF
PHP7で変わること ——言語仕様とエンジンの改善ポイント
Yoshio Hanawa
 
PDF
Apache Spark超入門 (Hadoop / Spark Conference Japan 2016 講演資料)
NTT DATA OSS Professional Services
 
PDF
Apache Sparkに手を出してヤケドしないための基本 ~「Apache Spark入門より」~ (デブサミ 2016 講演資料)
NTT DATA OSS Professional Services
 
PDF
GoによるWebアプリ開発のキホン
Akihiko Horiuchi
 
Metaprogramming in Scala 2.10, Eugene Burmako,
Vasil Remeniuk
 
Scalding: Twitter's Scala DSL for Hadoop/Cascading
johnynek
 
Scala in practice
Tomer Gabel
 
Scala profiling
Filippo Pacifici
 
Scala Talk at FOSDEM 2009
Martin Odersky
 
Procedure Typing for Scala
akuklev
 
BigData, Hadoop과 Node.js, R2
고포릿 default
 
RESTful Java
JavaCommunity.Org
 
Elixirと他言語の比較的紹介 ver.2
Tsunenori Oohara
 
Go言語によるwebアプリの作り方
Yasutaka Kawamoto
 
PHP7はなぜ速いのか
Yoshio Hanawa
 
java 8 람다식 소개와 의미 고찰
Sungchul Park
 
地獄のElixir(目黒スタートアップ勉強会)
Tsunenori Oohara
 
PHP7で変わること ——言語仕様とエンジンの改善ポイント
Yoshio Hanawa
 
Apache Spark超入門 (Hadoop / Spark Conference Japan 2016 講演資料)
NTT DATA OSS Professional Services
 
Apache Sparkに手を出してヤケドしないための基本 ~「Apache Spark入門より」~ (デブサミ 2016 講演資料)
NTT DATA OSS Professional Services
 
GoによるWebアプリ開発のキホン
Akihiko Horiuchi
 
Ad

Similar to Scala test (20)

PDF
Testing Spark and Scala
datamantra
 
PPTX
Testing in Scala by Adform research
Vasil Remeniuk
 
PPTX
Testing in Scala. Adform Research
Vasil Remeniuk
 
PDF
LambdaTest
John Nestor
 
PDF
Software Testing (in Scala): A Practitioner's Survey (Quickly)
Roberto Casadei
 
PPTX
Scala for Test Automation
rthanavarapu
 
PDF
Slawomir Kluz - ScalaTest from QA perspective (Quality Questions Conference)
Grand Parade Poland
 
PDF
Testing in the World of Functional Programming
Luka Jacobowitz
 
PPT
Testing Software Engineering systems end to end
arvindthangamani1
 
PPTX
Unit Testing in Java
Ahmed M. Gomaa
 
PPTX
How Scala promotes TDD
Shai Yallin
 
PPTX
L2624 labriola
michael.labriola
 
PPTX
Testing with Junit4
Amila Paranawithana
 
PPTX
The Test way
Mikhail Grinfeld
 
PDF
Unit testing with JUnit
Pokpitch Patcharadamrongkul
 
PPT
Junit
Manav Prasad
 
PDF
An Introduction to the World of Testing for Front-End Developers
FITC
 
PDF
FITC Web Unleashed 2017 - Introduction to the World of Testing for Front-End ...
Haris Mahmood
 
PDF
junit-160729073220 eclipse software testing.pdf
KomalSinghGill
 
PPSX
Junit
FAROOK Samath
 
Testing Spark and Scala
datamantra
 
Testing in Scala by Adform research
Vasil Remeniuk
 
Testing in Scala. Adform Research
Vasil Remeniuk
 
LambdaTest
John Nestor
 
Software Testing (in Scala): A Practitioner's Survey (Quickly)
Roberto Casadei
 
Scala for Test Automation
rthanavarapu
 
Slawomir Kluz - ScalaTest from QA perspective (Quality Questions Conference)
Grand Parade Poland
 
Testing in the World of Functional Programming
Luka Jacobowitz
 
Testing Software Engineering systems end to end
arvindthangamani1
 
Unit Testing in Java
Ahmed M. Gomaa
 
How Scala promotes TDD
Shai Yallin
 
L2624 labriola
michael.labriola
 
Testing with Junit4
Amila Paranawithana
 
The Test way
Mikhail Grinfeld
 
Unit testing with JUnit
Pokpitch Patcharadamrongkul
 
An Introduction to the World of Testing for Front-End Developers
FITC
 
FITC Web Unleashed 2017 - Introduction to the World of Testing for Front-End ...
Haris Mahmood
 
junit-160729073220 eclipse software testing.pdf
KomalSinghGill
 
Ad

More from Inphina Technologies (13)

PDF
Scala collections
Inphina Technologies
 
PPTX
Easy ORMness with Objectify-Appengine
Inphina Technologies
 
PDF
Cloud Foundry Impressions
Inphina Technologies
 
PDF
Cloud slam2011 multi-tenancy
Inphina Technologies
 
PDF
Google appenginemigrationcasestudy
Inphina Technologies
 
PDF
Preparing yourdataforcloud
Inphina Technologies
 
PDF
Multi-Tenancy in the Cloud
Inphina Technologies
 
PDF
Inphina at a glance
Inphina Technologies
 
PDF
Inphina cloud
Inphina Technologies
 
PDF
Multi-tenancy in the cloud
Inphina Technologies
 
PDF
Testing your application on Google App Engine
Inphina Technologies
 
PDF
Preparing your data for the cloud
Inphina Technologies
 
PDF
Getting started with jClouds
Inphina Technologies
 
Scala collections
Inphina Technologies
 
Easy ORMness with Objectify-Appengine
Inphina Technologies
 
Cloud Foundry Impressions
Inphina Technologies
 
Cloud slam2011 multi-tenancy
Inphina Technologies
 
Google appenginemigrationcasestudy
Inphina Technologies
 
Preparing yourdataforcloud
Inphina Technologies
 
Multi-Tenancy in the Cloud
Inphina Technologies
 
Inphina at a glance
Inphina Technologies
 
Inphina cloud
Inphina Technologies
 
Multi-tenancy in the cloud
Inphina Technologies
 
Testing your application on Google App Engine
Inphina Technologies
 
Preparing your data for the cloud
Inphina Technologies
 
Getting started with jClouds
Inphina Technologies
 

Recently uploaded (20)

PDF
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
Timothy Rottach - Ramp up on AI Use Cases, from Vector Search to AI Agents wi...
AWS Chicago
 
PDF
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
PDF
July Patch Tuesday
Ivanti
 
PDF
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
PDF
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
PDF
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
PDF
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
PDF
Python basic programing language for automation
DanialHabibi2
 
PDF
Log-Based Anomaly Detection: Enhancing System Reliability with Machine Learning
Mohammed BEKKOUCHE
 
PDF
From Code to Challenge: Crafting Skill-Based Games That Engage and Reward
aiyshauae
 
PDF
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
PPTX
UiPath Academic Alliance Educator Panels: Session 2 - Business Analyst Content
DianaGray10
 
PDF
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
PDF
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
PDF
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
PDF
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
PDF
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
PPTX
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
PDF
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
Timothy Rottach - Ramp up on AI Use Cases, from Vector Search to AI Agents wi...
AWS Chicago
 
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
July Patch Tuesday
Ivanti
 
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
Python basic programing language for automation
DanialHabibi2
 
Log-Based Anomaly Detection: Enhancing System Reliability with Machine Learning
Mohammed BEKKOUCHE
 
From Code to Challenge: Crafting Skill-Based Games That Engage and Reward
aiyshauae
 
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
UiPath Academic Alliance Educator Panels: Session 2 - Business Analyst Content
DianaGray10
 
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 

Scala test

  • 3. Introduction Continued .. With ScalaTest, we can test either Scala or Java code. Integrates with popular tools such as JUnit, TestNG, Ant, and Maven Designed to do different styles of testing like Behavior Driven Design for example
  • 4. Simple Junit4 Test package com.inphina.ibat.junit import org.scalatest.junit.AssertionsForJUnit import org.junit.Assert._ import org.junit.Test import org.junit.Before class SimpleJunit4Demo extends AssertionsForJUnit { var sb: StringBuilder = _ @Before def initialize() { sb = new StringBuilder("ScalaTest is ") } @Test def verifyEasy() { sb.append("easy!") assertEquals("ScalaTest is easy!", sb.toString) } }
  • 5. Concepts Three concepts: ● Suite: A collection of tests. A test is anything which has a name and can succeed or fail. ● Runner: ScalaTest provides a Runner application that can run Suites of tests ● Reporter: As the tests are run, events are fired to a reporter, it takes care of presenting results back to the user
  • 6. Scala Test Is Customizable Suite <<trait>> def expectedTestCount(Filter): Int def testNames: Set[String] def tags: Map[String, Set[String]] def nestedSuites: List[Suite] def run(Option[String], Reporter, ...) def runNestedSuites(Reporter, ...) def runTests(Option[String], Reporter, ...) def runTest(Reporter, ...) def withFixture(NoArgTest)
  • 7. Under The Hood When you run a Test in Scala Test you basically invoke run(Option[String], Reporter, .. ) on Suite Object. ● It then calls runNestedSuites(Reporter, ..) ● And it calls runTests(Option[String], Reporter, ..) runNestedSuites(Reporter, ..) : ● invokes nestedSuites() : List[Suite] to get a List of nested Suites runTests(Option[String], Reporter, ..) will call def testNames: Set[String] to get a Set of test names it needs to run. For each test name it calls runTest(Reporter, ...) It wraps the test code as a Function Object with a name and passes it to withFixture(NoArgTest) which actually runs the test.
  • 8. Pick a Core Trait
  • 9. Mix In Other Traits
  • 10. Traits in Scala Test • Suite • Funsuite • Spec • FlatSpec • WordSpec • FeatureSpec • Assertions • ShouldMatchers • MustMatchers
  • 11. Suite ➢ Traits approach to writing tests. Simply create classes extending Suite and define test methods. ➢ Test methods have names testXXXX. All methods must be public. ➢ Scala Test provides === operator. It is defined in Traits Assertions. Allows the failure report to include both right and left values.
  • 13. FunSuite ➢ For writing Functional Tests use FunSuite Fun => Functional Suite. ➢ "test" is a method defined in FunSuite Trait. Test name goes in parentheses and the test code goes in curly braces. ➢ The test code in curly braces is passed as a by-name parameter to "test" method which registers for later execution ➢ A FunSuite's life-cycle has two phases: the registration phase and the ready phase.
  • 15. Spec ➢ Trait that facilitates a “behavior-driven” style of development (BDD), in which tests are combined with text that specifies the behavior the tests verify. ➢ A Spec contains describe clauses and tests. We define a describe clause with describe, and a test with it. Both describe and it are methods, defined in Spec, which will be invoked by the primary constructor of StackSpec.
  • 17. FeatureSpec ➢ A suite of tests in which each test represents one scenario of a feature. ➢ FeatureSpec is intended for writing tests that are "higher level" than unit tests, for example, integration tests, functional tests, and acceptance tests. ➢ A FeatureSpec contains feature clauses and scenarios. we define a feature clause with “feature”, and a scenario with “scenario”. Both feature and scenario are methods, defined in FeatureSpec
  • 19. Summary Scala Test is a low risk way to get started ➢ with Scala ➢ Scala Test shows what Scala can leverage for our projects
  • 20. References ➢ Bill Venners presentation “Get Higher With Scala Test” ➢ Scala Test website www.scalatest.org