Scala test
Upcoming SlideShare
Loading in...5
×
 

Scala test

on

  • 4,579 views

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.

Statistics

Views

Total Views
4,579
Views on SlideShare
2,374
Embed Views
2,205

Actions

Likes
0
Downloads
18
Comments
0

7 Embeds 2,205

http://www.scoop.it 2170
http://meetumaltiar.wordpress.com 21
http://webcache.googleusercontent.com 3
http://www.docshut.com 3
http://www.linkedin.com 3
http://localhost 3
http://www.yatedo.com 2
More...

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Scala test Scala test Presentation Transcript

    • Scala TestMeetu Maltiar - mmaltiar@inphina.com
    • Introduction
    • 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
    • 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) }}
    • 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
    • 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 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.
    • 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 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.
    • Suite Demo
    • 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.
    • FunSuite Demo
    • 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.
    • Spec Demo
    • 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
    • FeatureSpec Demo
    • SummaryScala Test is a low risk way to get started➢with Scala➢ Scala Test shows what Scala canleverage for our projects
    • References➢ Bill Venners presentation “Get HigherWith Scala Test”➢ Scala Test website www.scalatest.org