SlideShare a Scribd company logo
1 of 20
Download to read offline
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

What's hot (20)

Code Kata: String Calculator in Flex
Code Kata: String Calculator in FlexCode Kata: String Calculator in Flex
Code Kata: String Calculator in Flex
 
Unit Testing with Python
Unit Testing with PythonUnit Testing with Python
Unit Testing with Python
 
All about unit testing using (power) mock
All about unit testing using (power) mockAll about unit testing using (power) mock
All about unit testing using (power) mock
 
Python testing
Python  testingPython  testing
Python testing
 
Introduction to JUnit
Introduction to JUnitIntroduction to JUnit
Introduction to JUnit
 
Python unit testing
Python unit testingPython unit testing
Python unit testing
 
05 junit
05 junit05 junit
05 junit
 
Java Unit Test - JUnit
Java Unit Test - JUnitJava Unit Test - JUnit
Java Unit Test - JUnit
 
Unit testing
Unit testingUnit testing
Unit testing
 
Unit testing with JUnit
Unit testing with JUnitUnit testing with JUnit
Unit testing with JUnit
 
TestNG vs Junit
TestNG vs JunitTestNG vs Junit
TestNG vs Junit
 
JUnit Pioneer
JUnit PioneerJUnit Pioneer
JUnit Pioneer
 
testng
testngtestng
testng
 
Junit and testNG
Junit and testNGJunit and testNG
Junit and testNG
 
Java Unit Testing
Java Unit TestingJava Unit Testing
Java Unit Testing
 
Unit Testing - Nakov's Talk @ VarnaConf 2013
Unit Testing - Nakov's Talk @ VarnaConf 2013Unit Testing - Nakov's Talk @ VarnaConf 2013
Unit Testing - Nakov's Talk @ VarnaConf 2013
 
New Microsoft Word Document.doc
New Microsoft Word Document.docNew Microsoft Word Document.doc
New Microsoft Word Document.doc
 
Krazykoder struts2 interceptors
Krazykoder struts2 interceptorsKrazykoder struts2 interceptors
Krazykoder struts2 interceptors
 
API Performance Testing
API Performance TestingAPI Performance Testing
API Performance Testing
 
JUnit 5
JUnit 5JUnit 5
JUnit 5
 

Viewers also liked

OPEN Houston Financials - 2013
OPEN Houston Financials - 2013OPEN Houston Financials - 2013
OPEN Houston Financials - 2013Zahid Rahman
 
Managing Development
Managing DevelopmentManaging Development
Managing DevelopmentAbby CHI
 
Scala categorytheory
Scala categorytheoryScala categorytheory
Scala categorytheoryMeetu Maltiar
 
Data structures in scala
Data structures in scalaData structures in scala
Data structures in scalaMeetu Maltiar
 
Getting Started With Scala
Getting Started With ScalaGetting Started With Scala
Getting Started With ScalaMeetu Maltiar
 
Teaching Students with Emojis, Emoticons, & Textspeak
Teaching Students with Emojis, Emoticons, & TextspeakTeaching Students with Emojis, Emoticons, & Textspeak
Teaching Students with Emojis, Emoticons, & TextspeakShelly Sanchez Terrell
 
Hype vs. Reality: The AI Explainer
Hype vs. Reality: The AI ExplainerHype vs. Reality: The AI Explainer
Hype vs. Reality: The AI ExplainerLuminary Labs
 
Study: The Future of VR, AR and Self-Driving Cars
Study: The Future of VR, AR and Self-Driving CarsStudy: The Future of VR, AR and Self-Driving Cars
Study: The Future of VR, AR and Self-Driving CarsLinkedIn
 

Viewers also liked (11)

OPEN Houston Financials - 2013
OPEN Houston Financials - 2013OPEN Houston Financials - 2013
OPEN Houston Financials - 2013
 
Managing Development
Managing DevelopmentManaging Development
Managing Development
 
Fitnesse With Scala
Fitnesse With ScalaFitnesse With Scala
Fitnesse With Scala
 
Scala categorytheory
Scala categorytheoryScala categorytheory
Scala categorytheory
 
Data structures in scala
Data structures in scalaData structures in scala
Data structures in scala
 
Akka 2.0 Reloaded
Akka 2.0 ReloadedAkka 2.0 Reloaded
Akka 2.0 Reloaded
 
Getting Started With Scala
Getting Started With ScalaGetting Started With Scala
Getting Started With Scala
 
Introducing Akka
Introducing AkkaIntroducing Akka
Introducing Akka
 
Teaching Students with Emojis, Emoticons, & Textspeak
Teaching Students with Emojis, Emoticons, & TextspeakTeaching Students with Emojis, Emoticons, & Textspeak
Teaching Students with Emojis, Emoticons, & Textspeak
 
Hype vs. Reality: The AI Explainer
Hype vs. Reality: The AI ExplainerHype vs. Reality: The AI Explainer
Hype vs. Reality: The AI Explainer
 
Study: The Future of VR, AR and Self-Driving Cars
Study: The Future of VR, AR and Self-Driving CarsStudy: The Future of VR, AR and Self-Driving Cars
Study: The Future of VR, AR and Self-Driving Cars
 

Similar to Scala test

Testing Spark and Scala
Testing Spark and ScalaTesting Spark and Scala
Testing Spark and Scaladatamantra
 
S313352 optimizing java device testing with automatic feature discovering
S313352 optimizing java device testing with automatic feature discoveringS313352 optimizing java device testing with automatic feature discovering
S313352 optimizing java device testing with automatic feature discoveringromanovfedor
 
Strategy-driven Test Generation with Open Source Frameworks
Strategy-driven Test Generation with Open Source FrameworksStrategy-driven Test Generation with Open Source Frameworks
Strategy-driven Test Generation with Open Source FrameworksDimitry Polivaev
 
Spring 3.1 and MVC Testing Support
Spring 3.1 and MVC Testing SupportSpring 3.1 and MVC Testing Support
Spring 3.1 and MVC Testing SupportSam Brannen
 
We Are All Testers Now: The Testing Pyramid and Front-End Development
We Are All Testers Now: The Testing Pyramid and Front-End DevelopmentWe Are All Testers Now: The Testing Pyramid and Front-End Development
We Are All Testers Now: The Testing Pyramid and Front-End DevelopmentAll Things Open
 
Grails unit testing
Grails unit testingGrails unit testing
Grails unit testingpleeps
 
Renaissance of JUnit - Introduction to JUnit 5
Renaissance of JUnit - Introduction to JUnit 5Renaissance of JUnit - Introduction to JUnit 5
Renaissance of JUnit - Introduction to JUnit 5Jimmy Lu
 
How Scala promotes TDD
How Scala promotes TDDHow Scala promotes TDD
How Scala promotes TDDShai Yallin
 
Describe's Full of It's
Describe's Full of It'sDescribe's Full of It's
Describe's Full of It'sJim Lynch
 
Unit Testing in .NET Core 7.0 with XUnit.pptx
Unit Testing in .NET Core 7.0 with XUnit.pptxUnit Testing in .NET Core 7.0 with XUnit.pptx
Unit Testing in .NET Core 7.0 with XUnit.pptxKnoldus Inc.
 
MT_01_unittest_python.pdf
MT_01_unittest_python.pdfMT_01_unittest_python.pdf
MT_01_unittest_python.pdfHans Jones
 
Quick tour to front end unit testing using jasmine
Quick tour to front end unit testing using jasmineQuick tour to front end unit testing using jasmine
Quick tour to front end unit testing using jasmineGil Fink
 
Intro to Testing in Zope, Plone
Intro to Testing in Zope, PloneIntro to Testing in Zope, Plone
Intro to Testing in Zope, PloneQuintagroup
 

Similar to Scala test (20)

Testing Spark and Scala
Testing Spark and ScalaTesting Spark and Scala
Testing Spark and Scala
 
S313352 optimizing java device testing with automatic feature discovering
S313352 optimizing java device testing with automatic feature discoveringS313352 optimizing java device testing with automatic feature discovering
S313352 optimizing java device testing with automatic feature discovering
 
Strategy-driven Test Generation with Open Source Frameworks
Strategy-driven Test Generation with Open Source FrameworksStrategy-driven Test Generation with Open Source Frameworks
Strategy-driven Test Generation with Open Source Frameworks
 
Good Practices On Test Automation
Good Practices On Test AutomationGood Practices On Test Automation
Good Practices On Test Automation
 
Gallio Crafting A Toolchain
Gallio Crafting A ToolchainGallio Crafting A Toolchain
Gallio Crafting A Toolchain
 
Spring 3.1 and MVC Testing Support
Spring 3.1 and MVC Testing SupportSpring 3.1 and MVC Testing Support
Spring 3.1 and MVC Testing Support
 
We Are All Testers Now: The Testing Pyramid and Front-End Development
We Are All Testers Now: The Testing Pyramid and Front-End DevelopmentWe Are All Testers Now: The Testing Pyramid and Front-End Development
We Are All Testers Now: The Testing Pyramid and Front-End Development
 
Grails unit testing
Grails unit testingGrails unit testing
Grails unit testing
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Annotations
AnnotationsAnnotations
Annotations
 
Automation tips
Automation tipsAutomation tips
Automation tips
 
Renaissance of JUnit - Introduction to JUnit 5
Renaissance of JUnit - Introduction to JUnit 5Renaissance of JUnit - Introduction to JUnit 5
Renaissance of JUnit - Introduction to JUnit 5
 
TestNG Framework
TestNG Framework TestNG Framework
TestNG Framework
 
How Scala promotes TDD
How Scala promotes TDDHow Scala promotes TDD
How Scala promotes TDD
 
Test driven development
Test driven developmentTest driven development
Test driven development
 
Describe's Full of It's
Describe's Full of It'sDescribe's Full of It's
Describe's Full of It's
 
Unit Testing in .NET Core 7.0 with XUnit.pptx
Unit Testing in .NET Core 7.0 with XUnit.pptxUnit Testing in .NET Core 7.0 with XUnit.pptx
Unit Testing in .NET Core 7.0 with XUnit.pptx
 
MT_01_unittest_python.pdf
MT_01_unittest_python.pdfMT_01_unittest_python.pdf
MT_01_unittest_python.pdf
 
Quick tour to front end unit testing using jasmine
Quick tour to front end unit testing using jasmineQuick tour to front end unit testing using jasmine
Quick tour to front end unit testing using jasmine
 
Intro to Testing in Zope, Plone
Intro to Testing in Zope, PloneIntro to Testing in Zope, Plone
Intro to Testing in Zope, Plone
 

Recently uploaded

Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterMydbops
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Mark Goldstein
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfpanagenda
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditSkynet Technologies
 
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Scott Andery
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesKari Kakkonen
 

Recently uploaded (20)

Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL Router
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance Audit
 
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examples
 

Scala test

  • 1. Scala Test Meetu Maltiar - mmaltiar@inphina.com
  • 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