SlideShare une entreprise Scribd logo
1  sur  18
Télécharger pour lire hors ligne
ScalaTest from QA
perspective
Sławomir Kluz
● functional language run on jvm
● you can write & mix code in Java
● project developed in Scala
● api tests, browser-based tests, performance test (Gatling)
● easy to switch from application code to test code
● it’s fun to learn and evaluate new tools
● data model
The Why story
Test styles
● xUnit
class SomeSuite extends FunSuite {
test("account creation test") {
}
}
● xUnit -> BDD
class SomeSuite extends FlatSpec {
behavior of "account service”
it should "be possible to create account" in {
}
"fresh account" should "have no roles" in {
}
}
Test styles
● Feature Given/When/Then
class SomeSuite extends FeatureSpec {
feature("account service list") {
scenario("empty list") {
Given("not accounts")
...
When("I ask for accounts")
...
Then("an empty list should be returned")
}
}
}
● Ruby’s RSpec
class SomeSuite extends FeatureSpec {
describe("account list page") {
scenario("empty list") {
it("should have size 0") {
}
}
}
}
Structural features
● pending tests
○ useful when creating test cases first - then implementation
○ listed in report
○ as a manual test cases list
it should "paginate account list" in pending
● informers, notifiers, alerters
○ visible in report
○ colored during test run (command line or CI)
○ logging alternative
alert("something went wrong")
info("something happened")
given("some initial data")
Structural features
● documenters
markup {
"""
This is very complicated test
----
It does something but who would remember what.
"""}
it should "be possible to create account" in {
}
}
Structural features
● tagging
it should "have valid schema" taggedAs (Schema, Smoke) in {
...
}
● runners
○ possibility to run existing JUnit & TestNG test (easy to migrate)
○ rerunning failed tests (second run)
○ retry on fail (under define conditions)
○ parallel run
○ IDE, maven, sbt
Structural features
● reporters
○ listeners for any kind of test event like: TestFailed, SuiteStaring, etc.
○ html, junit xml output formats - easy to integrate with CI
○ use case: custom ignored tests list
Test features
● withClue
withClue("active account") {
account.name should be("bar")
}
withClue("inactive account") {
account.name should be("bar")
}
org.scalatest.exceptions.TestFailedException: inactive account "[foo]" was not equal to "[bar]"
Test features
● matchers/assertions
○ easy to read API
○ clear failure messages
account.name should startWith ("bar")
“foo" did not start with substring "bar"
account.name should fullyMatch regex "^bar"
"foo" did not fully match the regular expression ^bar
account.id should (be > 10 and be < 11)
12 was greater than 10, but 12 was not less than 11
account.roles should have size 2
List(1, 2, 3) had size 3 instead of expected size 2
Test features
account.roles should contain atLeastOneOf (3, 1)
List(2, 4, 6) did not contain at least one of (3, 1)
account.roles should contain inOrder (2,6,4)
List(2, 4, 6) did not contain all of (2, 6, 4) in order
forAll(account.roles) {
_ should be > 3
}
org.scalatest.exceptions.TestFailedException: forAll failed, because:
at index 0, 2 was not greater than 3
in List(2, 4, 6)
Test features
account should have (
'id (12),
'name ("bar")
)
The name property had value "foo", instead of its expected value "bar", on object Account(12,foo,List(2, 4, 6))
inside(account) {
case Account(_, name, _) =>
name should startWith("bar")
}
Test features
● eventually
eventually {
val account = AccountService.getAccount(12)
account.activity shouldBe true
}
eventually(timeout(5 seconds), interval(10 millis)) {
val account = AccountService.getAccount(12)
account.activity shouldBe true
}
The code passed to eventually never returned normally. Attempted 474 times over 5.00807272 seconds. Last
failure message: false was not equal to true.
Scala features
● property base functional testing
Seq(
("/repository/file01.json", 2, (arg: String) => {arg should startWith("foo")}),
("/repository/file02.json", 3, (arg: String) => {arg should endWith("bar")})
).foreach{case (inputFilePath, expectedValue, validationFunction) => {
it should s"successfully process file $inputFilePath" in {
// do some common operations and assertions
validationFunction.apply(fileBody)
}
}}
Test features
● sharing fixtures
trait SmallFixtureRepository extends LazyLogging {
object Star {
trait AnonymousSession extends ProgramSession {
val anonymousSession = AccountsService.Star.createAnonymousSession(programSession)
}
trait CustomerAccount extends ProgramSession {
val customerAccount = AccountsService.Star.createCustomerAccountWithPassword(programSession)
}
trait CustomerSession extends CustomerAccount {
val customerSession = AccountsService.Star.createCustomerSession(programSession, customerAccount)
}
}
}
Test features
● sharing fixtures
it should "grant customer access" in new Star.CustomerSession {
println(customerSession)
}
it should "block anonymous session" in new Star.AnonymousSession {
println(anonymousSession)
}
it should "access bot types" in new Star.CustomerSession {
println(customerSession)
new Star.AnonymousSession {
println(anonymousSession)
}
}
Selenium DSL
click on name("name")
enter("Cheese!")
textField("q").value should be ("Cheese!")
checkbox("cbx1").select()
add cookie ("name1", "value1")
capture to "MyScreenShot"
Thanks

Contenu connexe

Tendances

Slaven tomac unit testing in angular js
Slaven tomac   unit testing in angular jsSlaven tomac   unit testing in angular js
Slaven tomac unit testing in angular js
Slaven Tomac
 

Tendances (20)

Utilising the data attribute
Utilising the data attributeUtilising the data attribute
Utilising the data attribute
 
Anonymous functions in JavaScript
Anonymous functions in JavaScriptAnonymous functions in JavaScript
Anonymous functions in JavaScript
 
Test-Driven Development of AngularJS Applications
Test-Driven Development of AngularJS ApplicationsTest-Driven Development of AngularJS Applications
Test-Driven Development of AngularJS Applications
 
Code generation with javac plugin
Code generation with javac pluginCode generation with javac plugin
Code generation with javac plugin
 
React 101
React 101React 101
React 101
 
React redux
React reduxReact redux
React redux
 
React&redux
React&reduxReact&redux
React&redux
 
Slaven tomac unit testing in angular js
Slaven tomac   unit testing in angular jsSlaven tomac   unit testing in angular js
Slaven tomac unit testing in angular js
 
Sessi
SessiSessi
Sessi
 
How Angular2 Can Improve Your AngularJS Apps Today!
How Angular2 Can Improve Your AngularJS Apps Today!How Angular2 Can Improve Your AngularJS Apps Today!
How Angular2 Can Improve Your AngularJS Apps Today!
 
Angular2 & ngrx/store: Game of States
Angular2 & ngrx/store: Game of StatesAngular2 & ngrx/store: Game of States
Angular2 & ngrx/store: Game of States
 
Reactive cocoa
Reactive cocoaReactive cocoa
Reactive cocoa
 
React и redux
React и reduxReact и redux
React и redux
 
Code generation for alternative languages
Code generation for alternative languagesCode generation for alternative languages
Code generation for alternative languages
 
Practical QML - Key Navigation, Dynamic Language and Theme Change
Practical QML - Key Navigation, Dynamic Language and Theme ChangePractical QML - Key Navigation, Dynamic Language and Theme Change
Practical QML - Key Navigation, Dynamic Language and Theme Change
 
VBA API for scriptDB primer
VBA API for scriptDB primerVBA API for scriptDB primer
VBA API for scriptDB primer
 
A Blueprint for Scala Microservices
A Blueprint for Scala MicroservicesA Blueprint for Scala Microservices
A Blueprint for Scala Microservices
 
Building the an End-to-End ASP.NET MVC 4, Entity Framework, HTML5, jQuery app...
Building the an End-to-End ASP.NET MVC 4, Entity Framework, HTML5, jQuery app...Building the an End-to-End ASP.NET MVC 4, Entity Framework, HTML5, jQuery app...
Building the an End-to-End ASP.NET MVC 4, Entity Framework, HTML5, jQuery app...
 
jQuery - Chapter 5 - Ajax
jQuery - Chapter 5 -  AjaxjQuery - Chapter 5 -  Ajax
jQuery - Chapter 5 - Ajax
 
How to unit test your React/Redux app
How to unit test your React/Redux appHow to unit test your React/Redux app
How to unit test your React/Redux app
 

Similaire à Slawomir Kluz - ScalaTest from QA perspective (Quality Questions Conference)

JavaScript: Patterns, Part 2
JavaScript: Patterns, Part  2JavaScript: Patterns, Part  2
JavaScript: Patterns, Part 2
Chris Farrell
 
ADG Poznań - Kotlin for Android developers
ADG Poznań - Kotlin for Android developersADG Poznań - Kotlin for Android developers
ADG Poznań - Kotlin for Android developers
Bartosz Kosarzycki
 
Tdd for BT E2E test community
Tdd for BT E2E test communityTdd for BT E2E test community
Tdd for BT E2E test community
Kerry Buckley
 

Similaire à Slawomir Kluz - ScalaTest from QA perspective (Quality Questions Conference) (20)

Apache Spark in your likeness - low and high level customization
Apache Spark in your likeness - low and high level customizationApache Spark in your likeness - low and high level customization
Apache Spark in your likeness - low and high level customization
 
RESTful API using scalaz (3)
RESTful API using scalaz (3)RESTful API using scalaz (3)
RESTful API using scalaz (3)
 
Ruby on Rails testing with Rspec
Ruby on Rails testing with RspecRuby on Rails testing with Rspec
Ruby on Rails testing with Rspec
 
Basics of Java Script (JS)
Basics of Java Script (JS)Basics of Java Script (JS)
Basics of Java Script (JS)
 
JavaScript: Patterns, Part 2
JavaScript: Patterns, Part  2JavaScript: Patterns, Part  2
JavaScript: Patterns, Part 2
 
Iterative architecture
Iterative architectureIterative architecture
Iterative architecture
 
ADG Poznań - Kotlin for Android developers
ADG Poznań - Kotlin for Android developersADG Poznań - Kotlin for Android developers
ADG Poznań - Kotlin for Android developers
 
Java best practices
Java best practicesJava best practices
Java best practices
 
Kotlin Developer Starter in Android projects
Kotlin Developer Starter in Android projectsKotlin Developer Starter in Android projects
Kotlin Developer Starter in Android projects
 
Kotlin Developer Starter in Android - STX Next Lightning Talks - Feb 12, 2016
Kotlin Developer Starter in Android - STX Next Lightning Talks - Feb 12, 2016Kotlin Developer Starter in Android - STX Next Lightning Talks - Feb 12, 2016
Kotlin Developer Starter in Android - STX Next Lightning Talks - Feb 12, 2016
 
Clean Code: Chapter 3 Function
Clean Code: Chapter 3 FunctionClean Code: Chapter 3 Function
Clean Code: Chapter 3 Function
 
Testing in JavaScript
Testing in JavaScriptTesting in JavaScript
Testing in JavaScript
 
Tdd for BT E2E test community
Tdd for BT E2E test communityTdd for BT E2E test community
Tdd for BT E2E test community
 
Testing in Scala. Adform Research
Testing in Scala. Adform ResearchTesting in Scala. Adform Research
Testing in Scala. Adform Research
 
Testing in Scala by Adform research
Testing in Scala by Adform researchTesting in Scala by Adform research
Testing in Scala by Adform research
 
Scala active record
Scala active recordScala active record
Scala active record
 
Test strategies for data processing pipelines, v2.0
Test strategies for data processing pipelines, v2.0Test strategies for data processing pipelines, v2.0
Test strategies for data processing pipelines, v2.0
 
GPerf Using Jesque
GPerf Using JesqueGPerf Using Jesque
GPerf Using Jesque
 
AngularJS - Services
AngularJS - ServicesAngularJS - Services
AngularJS - Services
 
Test strategies for data processing pipelines
Test strategies for data processing pipelinesTest strategies for data processing pipelines
Test strategies for data processing pipelines
 

Plus de Grand Parade Poland

Plus de Grand Parade Poland (14)

Making Games in WebGL - Aro Wierzbowski & Tomasz Szepczyński
Making Games in WebGL - Aro Wierzbowski & Tomasz SzepczyńskiMaking Games in WebGL - Aro Wierzbowski & Tomasz Szepczyński
Making Games in WebGL - Aro Wierzbowski & Tomasz Szepczyński
 
Mobile Team on Daily basis - Kamil Burczyk & Michał Ćwikliński (Mobiconf2017)
Mobile Team on Daily basis - Kamil Burczyk & Michał Ćwikliński (Mobiconf2017)Mobile Team on Daily basis - Kamil Burczyk & Michał Ćwikliński (Mobiconf2017)
Mobile Team on Daily basis - Kamil Burczyk & Michał Ćwikliński (Mobiconf2017)
 
Css encapsulation strategies | Marcin Mazurek
Css encapsulation strategies | Marcin MazurekCss encapsulation strategies | Marcin Mazurek
Css encapsulation strategies | Marcin Mazurek
 
Reason - introduction to language and its ecosystem | Łukasz Strączyński
Reason - introduction to language and its ecosystem | Łukasz StrączyńskiReason - introduction to language and its ecosystem | Łukasz Strączyński
Reason - introduction to language and its ecosystem | Łukasz Strączyński
 
Thinking in Graphs - GraphQL problems and more - Maciej Rybaniec (23.06.2017)
Thinking in Graphs - GraphQL problems and more - Maciej Rybaniec (23.06.2017)Thinking in Graphs - GraphQL problems and more - Maciej Rybaniec (23.06.2017)
Thinking in Graphs - GraphQL problems and more - Maciej Rybaniec (23.06.2017)
 
Introduction to React Native - Marcin Mazurek (09.06.2017)
Introduction to React Native - Marcin Mazurek (09.06.2017)Introduction to React Native - Marcin Mazurek (09.06.2017)
Introduction to React Native - Marcin Mazurek (09.06.2017)
 
Reactive Programming with RxJava
Reactive Programming with RxJavaReactive Programming with RxJava
Reactive Programming with RxJava
 
Pawel Cygal - SQL Injection and XSS - Basics (Quality Questions Conference)
Pawel Cygal - SQL Injection and XSS - Basics (Quality Questions Conference)Pawel Cygal - SQL Injection and XSS - Basics (Quality Questions Conference)
Pawel Cygal - SQL Injection and XSS - Basics (Quality Questions Conference)
 
Mateusz Gruszczynski - Performance tests in Gatling (Quality Questions Confer...
Mateusz Gruszczynski - Performance tests in Gatling (Quality Questions Confer...Mateusz Gruszczynski - Performance tests in Gatling (Quality Questions Confer...
Mateusz Gruszczynski - Performance tests in Gatling (Quality Questions Confer...
 
Krzysztof Skarbinski - Automated tests in Python (Quality Questions Conference)
Krzysztof Skarbinski - Automated tests in Python (Quality Questions Conference)Krzysztof Skarbinski - Automated tests in Python (Quality Questions Conference)
Krzysztof Skarbinski - Automated tests in Python (Quality Questions Conference)
 
Rafał Machnik - CQRS as a performance and security booster (Quality Questions...
Rafał Machnik - CQRS as a performance and security booster (Quality Questions...Rafał Machnik - CQRS as a performance and security booster (Quality Questions...
Rafał Machnik - CQRS as a performance and security booster (Quality Questions...
 
Steve Bond - Managing the Threats in Online Gaming (Quality Questions Confere...
Steve Bond - Managing the Threats in Online Gaming (Quality Questions Confere...Steve Bond - Managing the Threats in Online Gaming (Quality Questions Confere...
Steve Bond - Managing the Threats in Online Gaming (Quality Questions Confere...
 
React-redux server side rendering enchanted with varnish-cache for the fastes...
React-redux server side rendering enchanted with varnish-cache for the fastes...React-redux server side rendering enchanted with varnish-cache for the fastes...
React-redux server side rendering enchanted with varnish-cache for the fastes...
 
Wielomilionowy Ruch na Wordpressie - Łukasz Wilczak & Piotr Federowicz (WordC...
Wielomilionowy Ruch na Wordpressie - Łukasz Wilczak & Piotr Federowicz (WordC...Wielomilionowy Ruch na Wordpressie - Łukasz Wilczak & Piotr Federowicz (WordC...
Wielomilionowy Ruch na Wordpressie - Łukasz Wilczak & Piotr Federowicz (WordC...
 

Dernier

+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@
 

Dernier (20)

Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
+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...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
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
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
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
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
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
 
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
 
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...
 
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...
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.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
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 

Slawomir Kluz - ScalaTest from QA perspective (Quality Questions Conference)

  • 2. ● functional language run on jvm ● you can write & mix code in Java ● project developed in Scala ● api tests, browser-based tests, performance test (Gatling) ● easy to switch from application code to test code ● it’s fun to learn and evaluate new tools ● data model The Why story
  • 3. Test styles ● xUnit class SomeSuite extends FunSuite { test("account creation test") { } } ● xUnit -> BDD class SomeSuite extends FlatSpec { behavior of "account service” it should "be possible to create account" in { } "fresh account" should "have no roles" in { } }
  • 4. Test styles ● Feature Given/When/Then class SomeSuite extends FeatureSpec { feature("account service list") { scenario("empty list") { Given("not accounts") ... When("I ask for accounts") ... Then("an empty list should be returned") } } } ● Ruby’s RSpec class SomeSuite extends FeatureSpec { describe("account list page") { scenario("empty list") { it("should have size 0") { } } } }
  • 5. Structural features ● pending tests ○ useful when creating test cases first - then implementation ○ listed in report ○ as a manual test cases list it should "paginate account list" in pending ● informers, notifiers, alerters ○ visible in report ○ colored during test run (command line or CI) ○ logging alternative alert("something went wrong") info("something happened") given("some initial data")
  • 6. Structural features ● documenters markup { """ This is very complicated test ---- It does something but who would remember what. """} it should "be possible to create account" in { } }
  • 7. Structural features ● tagging it should "have valid schema" taggedAs (Schema, Smoke) in { ... } ● runners ○ possibility to run existing JUnit & TestNG test (easy to migrate) ○ rerunning failed tests (second run) ○ retry on fail (under define conditions) ○ parallel run ○ IDE, maven, sbt
  • 8. Structural features ● reporters ○ listeners for any kind of test event like: TestFailed, SuiteStaring, etc. ○ html, junit xml output formats - easy to integrate with CI ○ use case: custom ignored tests list
  • 9. Test features ● withClue withClue("active account") { account.name should be("bar") } withClue("inactive account") { account.name should be("bar") } org.scalatest.exceptions.TestFailedException: inactive account "[foo]" was not equal to "[bar]"
  • 10. Test features ● matchers/assertions ○ easy to read API ○ clear failure messages account.name should startWith ("bar") “foo" did not start with substring "bar" account.name should fullyMatch regex "^bar" "foo" did not fully match the regular expression ^bar account.id should (be > 10 and be < 11) 12 was greater than 10, but 12 was not less than 11 account.roles should have size 2 List(1, 2, 3) had size 3 instead of expected size 2
  • 11. Test features account.roles should contain atLeastOneOf (3, 1) List(2, 4, 6) did not contain at least one of (3, 1) account.roles should contain inOrder (2,6,4) List(2, 4, 6) did not contain all of (2, 6, 4) in order forAll(account.roles) { _ should be > 3 } org.scalatest.exceptions.TestFailedException: forAll failed, because: at index 0, 2 was not greater than 3 in List(2, 4, 6)
  • 12. Test features account should have ( 'id (12), 'name ("bar") ) The name property had value "foo", instead of its expected value "bar", on object Account(12,foo,List(2, 4, 6)) inside(account) { case Account(_, name, _) => name should startWith("bar") }
  • 13. Test features ● eventually eventually { val account = AccountService.getAccount(12) account.activity shouldBe true } eventually(timeout(5 seconds), interval(10 millis)) { val account = AccountService.getAccount(12) account.activity shouldBe true } The code passed to eventually never returned normally. Attempted 474 times over 5.00807272 seconds. Last failure message: false was not equal to true.
  • 14. Scala features ● property base functional testing Seq( ("/repository/file01.json", 2, (arg: String) => {arg should startWith("foo")}), ("/repository/file02.json", 3, (arg: String) => {arg should endWith("bar")}) ).foreach{case (inputFilePath, expectedValue, validationFunction) => { it should s"successfully process file $inputFilePath" in { // do some common operations and assertions validationFunction.apply(fileBody) } }}
  • 15. Test features ● sharing fixtures trait SmallFixtureRepository extends LazyLogging { object Star { trait AnonymousSession extends ProgramSession { val anonymousSession = AccountsService.Star.createAnonymousSession(programSession) } trait CustomerAccount extends ProgramSession { val customerAccount = AccountsService.Star.createCustomerAccountWithPassword(programSession) } trait CustomerSession extends CustomerAccount { val customerSession = AccountsService.Star.createCustomerSession(programSession, customerAccount) } } }
  • 16. Test features ● sharing fixtures it should "grant customer access" in new Star.CustomerSession { println(customerSession) } it should "block anonymous session" in new Star.AnonymousSession { println(anonymousSession) } it should "access bot types" in new Star.CustomerSession { println(customerSession) new Star.AnonymousSession { println(anonymousSession) } }
  • 17. Selenium DSL click on name("name") enter("Cheese!") textField("q").value should be ("Cheese!") checkbox("cbx1").select() add cookie ("name1", "value1") capture to "MyScreenShot"