SlideShare ist ein Scribd-Unternehmen logo
1 von 20
Downloaden Sie, um offline zu lesen
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

Weitere ähnliche Inhalte

Was ist angesagt?

Was ist angesagt? (20)

Scala Intro
Scala IntroScala Intro
Scala Intro
 
Scala
ScalaScala
Scala
 
Scala
ScalaScala
Scala
 
Stepping Up : A Brief Intro to Scala
Stepping Up : A Brief Intro to ScalaStepping Up : A Brief Intro to Scala
Stepping Up : A Brief Intro to Scala
 
New Features in JDK 8
New Features in JDK 8New Features in JDK 8
New Features in JDK 8
 
Scala coated JVM
Scala coated JVMScala coated JVM
Scala coated JVM
 
Scala fundamentals
Scala fundamentalsScala fundamentals
Scala fundamentals
 
Google06
Google06Google06
Google06
 
Workshop Scala
Workshop ScalaWorkshop Scala
Workshop Scala
 
Scala @ TechMeetup Edinburgh
Scala @ TechMeetup EdinburghScala @ TechMeetup Edinburgh
Scala @ TechMeetup Edinburgh
 
A Tour Of Scala
A Tour Of ScalaA Tour Of Scala
A Tour Of Scala
 
Scala - brief intro
Scala - brief introScala - brief intro
Scala - brief intro
 
Java 8 features
Java 8 featuresJava 8 features
Java 8 features
 
Scala in a nutshell by venkat
Scala in a nutshell by venkatScala in a nutshell by venkat
Scala in a nutshell by venkat
 
Pragmatic Real-World Scala (short version)
Pragmatic Real-World Scala (short version)Pragmatic Real-World Scala (short version)
Pragmatic Real-World Scala (short version)
 
Core java Essentials
Core java EssentialsCore java Essentials
Core java Essentials
 
Java tutorial for Beginners and Entry Level
Java tutorial for Beginners and Entry LevelJava tutorial for Beginners and Entry Level
Java tutorial for Beginners and Entry Level
 
The Evolution of Scala
The Evolution of ScalaThe Evolution of Scala
The Evolution of Scala
 
Functional Programming In Practice
Functional Programming In PracticeFunctional Programming In Practice
Functional Programming In Practice
 
Java 8 Feature Preview
Java 8 Feature PreviewJava 8 Feature Preview
Java 8 Feature Preview
 

Andere mochten auch

Andere mochten auch (14)

Scalding: Twitter's Scala DSL for Hadoop/Cascading
Scalding: Twitter's Scala DSL for Hadoop/CascadingScalding: Twitter's Scala DSL for Hadoop/Cascading
Scalding: Twitter's Scala DSL for Hadoop/Cascading
 
Scala in practice
Scala in practiceScala in practice
Scala in practice
 
Scala profiling
Scala profilingScala profiling
Scala profiling
 
BigData, Hadoop과 Node.js, R2
BigData, Hadoop과 Node.js, R2BigData, Hadoop과 Node.js, R2
BigData, Hadoop과 Node.js, R2
 
RESTful Java
RESTful JavaRESTful Java
RESTful Java
 
Elixirと他言語の比較的紹介 ver.2
Elixirと他言語の比較的紹介ver.2Elixirと他言語の比較的紹介ver.2
Elixirと他言語の比較的紹介 ver.2
 
Go言語によるwebアプリの作り方
Go言語によるwebアプリの作り方Go言語によるwebアプリの作り方
Go言語によるwebアプリの作り方
 
PHP7はなぜ速いのか
PHP7はなぜ速いのかPHP7はなぜ速いのか
PHP7はなぜ速いのか
 
java 8 람다식 소개와 의미 고찰
java 8 람다식 소개와 의미 고찰java 8 람다식 소개와 의미 고찰
java 8 람다식 소개와 의미 고찰
 
地獄のElixir(目黒スタートアップ勉強会)
地獄のElixir(目黒スタートアップ勉強会)地獄のElixir(目黒スタートアップ勉強会)
地獄のElixir(目黒スタートアップ勉強会)
 
PHP7で変わること ——言語仕様とエンジンの改善ポイント
PHP7で変わること ——言語仕様とエンジンの改善ポイントPHP7で変わること ——言語仕様とエンジンの改善ポイント
PHP7で変わること ——言語仕様とエンジンの改善ポイント
 
Apache Spark超入門 (Hadoop / Spark Conference Japan 2016 講演資料)
Apache Spark超入門 (Hadoop / Spark Conference Japan 2016 講演資料)Apache Spark超入門 (Hadoop / Spark Conference Japan 2016 講演資料)
Apache Spark超入門 (Hadoop / Spark Conference Japan 2016 講演資料)
 
Apache Sparkに手を出してヤケドしないための基本 ~「Apache Spark入門より」~ (デブサミ 2016 講演資料)
Apache Sparkに手を出してヤケドしないための基本 ~「Apache Spark入門より」~ (デブサミ 2016 講演資料)Apache Sparkに手を出してヤケドしないための基本 ~「Apache Spark入門より」~ (デブサミ 2016 講演資料)
Apache Sparkに手を出してヤケドしないための基本 ~「Apache Spark入門より」~ (デブサミ 2016 講演資料)
 
GoによるWebアプリ開発のキホン
GoによるWebアプリ開発のキホンGoによるWebアプリ開発のキホン
GoによるWebアプリ開発のキホン
 

Ähnlich wie Scala test

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
Dimitry Polivaev
 
Code Kata: String Calculator in Flex
Code Kata: String Calculator in FlexCode Kata: String Calculator in Flex
Code Kata: String Calculator in Flex
Chris Farrell
 

Ähnlich wie 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
 
Unit testing
Unit testingUnit testing
Unit testing
 
Java Unit Test - JUnit
Java Unit Test - JUnitJava Unit Test - JUnit
Java Unit Test - JUnit
 
Unit testing with JUnit
Unit testing with JUnitUnit testing with JUnit
Unit testing with JUnit
 
Good Practices On Test Automation
Good Practices On Test AutomationGood Practices On Test Automation
Good Practices On Test Automation
 
Code Kata: String Calculator in Flex
Code Kata: String Calculator in FlexCode Kata: String Calculator in Flex
Code Kata: String Calculator in Flex
 
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
 

Mehr von Inphina Technologies

Google appenginemigrationcasestudy
Google appenginemigrationcasestudyGoogle appenginemigrationcasestudy
Google appenginemigrationcasestudy
Inphina Technologies
 

Mehr von Inphina Technologies (13)

Scala collections
Scala collectionsScala collections
Scala collections
 
Easy ORMness with Objectify-Appengine
Easy ORMness with Objectify-AppengineEasy ORMness with Objectify-Appengine
Easy ORMness with Objectify-Appengine
 
Cloud Foundry Impressions
Cloud Foundry Impressions Cloud Foundry Impressions
Cloud Foundry Impressions
 
Cloud slam2011 multi-tenancy
Cloud slam2011 multi-tenancyCloud slam2011 multi-tenancy
Cloud slam2011 multi-tenancy
 
Google appenginemigrationcasestudy
Google appenginemigrationcasestudyGoogle appenginemigrationcasestudy
Google appenginemigrationcasestudy
 
Preparing yourdataforcloud
Preparing yourdataforcloudPreparing yourdataforcloud
Preparing yourdataforcloud
 
Multi-Tenancy in the Cloud
Multi-Tenancy in the CloudMulti-Tenancy in the Cloud
Multi-Tenancy in the Cloud
 
Inphina at a glance
Inphina at a glanceInphina at a glance
Inphina at a glance
 
Inphina cloud
Inphina cloudInphina cloud
Inphina cloud
 
Multi-tenancy in the cloud
Multi-tenancy in the cloudMulti-tenancy in the cloud
Multi-tenancy in the cloud
 
Testing your application on Google App Engine
Testing your application on Google App EngineTesting your application on Google App Engine
Testing your application on Google App Engine
 
Preparing your data for the cloud
Preparing your data for the cloudPreparing your data for the cloud
Preparing your data for the cloud
 
Getting started with jClouds
Getting started with jCloudsGetting started with jClouds
Getting started with jClouds
 

Kürzlich hochgeladen

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Kürzlich hochgeladen (20)

Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 

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