Your SlideShare is downloading. ×
  • Like
Scala test
Upcoming SlideShare
Loading in...5

Thanks for flagging this SlideShare!

Oops! An error has occurred.


Now you can save presentations on your phone or tablet

Available for both IPhone and Android

Text the download link to your phone

Standard text messaging rates apply

Scala test allows you to test your application written in Java and Scala.

Scala test allows you to test your application written in Java and Scala.

Published in Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads


Total Views
On SlideShare
From Embeds
Number of Embeds



Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

    No notes for slide


  • 1. Scala TestMeetu Maltiar -
  • 2. Introduction
  • 3. Introduction Continued ..With ScalaTest, we can test either Scala or Javacode.Integrates with popular tools such as JUnit,TestNG, Ant, and MavenDesigned to do different styles of testing likeBehavior Driven Design for example
  • 4. Simple Junit4 Testpackage com.inphina.ibat.junitimport org.scalatest.junit.AssertionsForJUnitimport org.junit.Assert._import org.junit.Testimport org.junit.Beforeclass 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. ConceptsThree concepts:● Suite: A collection of tests. A test is anything which has a nameand can succeed or fail.● Runner: ScalaTest provides a Runner application that can runSuites of tests● Reporter: As the tests are run, events are fired to a reporter, ittakes 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 HoodWhen you run a Test in Scala Test you basically invokerun(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 SuitesrunTests(Option[String], Reporter, ..) will call def testNames:Set[String] to get a Set of test names it needs to run. For each testname it calls runTest(Reporter, ...) It wraps the test code as aFunction 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 createclasses extending Suite and define test methods.➢ Test methods have names testXXXX. All methodsmust be public.➢ Scala Test provides === operator. It is defined inTraits Assertions. Allows the failure report to includeboth right and left values.
  • 12. Suite Demo
  • 13. FunSuite➢ For writing Functional Tests use FunSuite Fun =>Functional Suite.➢ "test" is a method defined in FunSuite Trait. Test namegoes in parentheses and the test code goes in curlybraces.➢ The test code in curly braces is passed as a by-nameparameter to "test" method which registers for laterexecution➢ A FunSuites life-cycle has two phases: the registrationphase and the ready phase.
  • 14. FunSuite Demo
  • 15. Spec➢ Trait that facilitates a “behavior-driven” style ofdevelopment (BDD), in which tests are combined with textthat specifies the behavior the tests verify.➢ A Spec contains describe clauses and tests. We definea describe clause with describe, and a test with it. Bothdescribe and it are methods, defined in Spec, which willbe invoked by the primary constructor of StackSpec.
  • 16. Spec Demo
  • 17. FeatureSpec➢ A suite of tests in which each test represents onescenario of a feature.➢ FeatureSpec is intended for writing tests that are "higherlevel" 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 scenariowith “scenario”. Both feature and scenario are methods,defined in FeatureSpec
  • 18. FeatureSpec Demo
  • 19. SummaryScala Test is a low risk way to get started➢with Scala➢ Scala Test shows what Scala canleverage for our projects
  • 20. References➢ Bill Venners presentation “Get HigherWith Scala Test”➢ Scala Test website