{"id":209578,"date":"2014-01-19T16:05:03","date_gmt":"2014-01-19T12:05:03","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=209578"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=209578","title":{"rendered":"<span class=\"post_title\">\u041d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u0432\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0432 Scalatest<\/span>"},"content":{"rendered":"<div class=\"content html_format\"> \t\t\tScalatest \u2014 \u044d\u0442\u043e \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a \u0434\u043b\u044f \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439, \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u044e\u0449\u0438\u0439 \u0440\u0430\u0437\u043d\u044b\u0435 \u0441\u0442\u0438\u043b\u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0442\u0435\u0441\u0442\u043e\u0432 \u0438 \u043b\u0435\u0433\u043a\u043e \u0438\u043d\u0442\u0435\u0433\u0440\u0438\u0440\u0443\u044e\u0449\u0438\u0439\u0441\u044f \u0441 \u0434\u0440\u0443\u0433\u0438\u043c\u0438 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u0430\u043c\u0438 \u0434\u043b\u044f JVM, \u0432\u043a\u043b\u044e\u0447\u0430\u044f IDE \u0438 maven.<br \/>  <a name=\"habracut\"><\/a><br \/>  \u041a\u0430\u0436\u0434\u044b\u0439 \u0438\u0437 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u043c\u044b\u0445 \u0441\u0442\u0438\u043b\u0435\u0439 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0432 Scalatest \u0441\u043e\u0437\u0434\u0430\u043d \u0434\u043b\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0432 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0445 \u0446\u0435\u043b\u044f\u0445. \u0414\u043b\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0438\u0437 \u0441\u0442\u0438\u043b\u0435\u0439 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043a\u043b\u0430\u0441\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c trait, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d \u044d\u0442\u043e\u0442 \u0441\u0442\u0438\u043b\u044c \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f. \u0412\u044b\u0431\u0440\u0430\u043d\u043d\u044b\u0439 \u0441\u0442\u0438\u043b\u044c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u043e, \u043a\u0430\u043a \u0432\u044b\u0433\u043b\u044f\u0434\u044f\u0442 \u0434\u0435\u043a\u043b\u0430\u0440\u0430\u0446\u0438\u0438 \u0442\u0435\u0441\u0442\u043e\u0432, \u0432\u0441\u0435 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0430 \u0431\u0443\u0434\u0443\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u043e, \u0432\u043d\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a\u043e\u0439 \u0438\u0437 \u0441\u0442\u0438\u043b\u0435\u0439 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0431\u044b\u043b \u0432\u044b\u0431\u0440\u0430\u043d. \u0410\u0432\u0442\u043e\u0440\u044b \u0440\u0435\u043a\u043e\u043c\u043c\u0435\u043d\u0434\u0443\u044e\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c FlatSpec \u0434\u043b\u044f \u044e\u043d\u0438\u0442-\u0442\u0435\u0441\u0442\u043e\u0432 \u0438 \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u043e\u0433\u043e \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u0438 FeatureSpec \u0434\u043b\u044f \u043f\u0440\u0438\u0435\u043c\u043e\u0447\u043d\u043e\u0433\u043e \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0430\u0440\u0443 \u0434\u0440\u0443\u0433\u0438\u0445 \u0441\u0442\u0438\u043b\u0435\u0439 \u044f \u0443\u043a\u0430\u0436\u0443 \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u0430:<\/p>\n<h5>FlatSpec<\/h5>\n<p>  FlatSpec \u2014 \u0445\u043e\u0440\u043e\u0448\u0438\u0439 \u0448\u0430\u0433 \u0432\u043f\u0435\u0440\u0451\u0434 \u0434\u043b\u044f \u043a\u043e\u043c\u0430\u043d\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0445\u043e\u0442\u044f\u0442 \u043f\u0435\u0440\u0435\u0439\u0442\u0438 \u043e\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f xUnit \u0438 \u0434\u0440\u0443\u0433\u0438\u0445 \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0445 \u0444\u0440\u0435\u0438\u043c\u0432\u043e\u0440\u043a\u043e\u0432 \u043a \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0432\u0430\u043d\u0438\u044e BDD, FlatSpec \u2014 \u044d\u0442\u043e DSL, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0449\u0438\u0439 \u043f\u0438\u0441\u0430\u0442\u044c \u0442\u0435\u0441\u0442\u044b \u0432 \u0432\u0438\u0434\u0435 \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0431\u043e\u043b\u0435\u0435 \u043f\u0440\u0438\u0431\u043b\u0438\u0436\u0451\u043d\u043d\u043e\u043c \u043a \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044e \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u0442\u0435\u0441\u0442\u0438\u0440\u0443\u0435\u043c\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430.  <\/p>\n<pre><code class=\"scala\">import org.scalatest.FlatSpec  class SetSpec extends FlatSpec {         &quot;An empty Set&quot; should &quot;have size 0&quot; in {     assert(Set.empty.size == 0)   }    it should &quot;produce NoSuchElementException when head is invoked&quot; in {     intercept[NoSuchElementException] {       Set.empty.head     }   } } <\/code><\/pre>\n<h5>FeatureSpec<\/h5>\n<p>  FeatureSpec \u043d\u0430\u0446\u0435\u043b\u0435\u043d \u043d\u0430 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043f\u0440\u0438\u0435\u043c\u043e\u0447\u043d\u044b\u0445 \u0442\u0435\u0441\u0442\u043e\u0432, \u043e\u0431\u043b\u0435\u0433\u0447\u0430\u044f \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u0430\u043c, \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0449\u0438\u043c \u0441 \u043d\u0435 \u043f\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u0430\u043c\u0438 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u043f\u0440\u0438\u0435\u043c\u043e\u0447\u043d\u044b\u0445 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u0439.  <\/p>\n<pre><code class=\"scala\">import org.scalatest._  class TVSet {   private var on: Boolean = false   def isOn: Boolean = on   def pressPowerButton() {     on = !on   } }  class TVSetSpec extends FeatureSpec with GivenWhenThen {    info(&quot;As a TV set owner&quot;)   info(&quot;I want to be able to turn the TV on and off&quot;)   info(&quot;So I can watch TV when I want&quot;)   info(&quot;And save energy when I'm not watching TV&quot;)    feature(&quot;TV power button&quot;) {     scenario(&quot;User presses power button when TV is off&quot;) {        Given(&quot;a TV set that is switched off&quot;)       val tv = new TVSet       assert(!tv.isOn)        When(&quot;the power button is pressed&quot;)       tv.pressPowerButton()        Then(&quot;the TV should switch on&quot;)       assert(tv.isOn)     }      scenario(&quot;User presses power button when TV is on&quot;) {        Given(&quot;a TV set that is switched on&quot;)       val tv = new TVSet       tv.pressPowerButton()       assert(tv.isOn)        When(&quot;the power button is pressed&quot;)       tv.pressPowerButton()        Then(&quot;the TV should switch off&quot;)       assert(!tv.isOn)     }   } } <\/code><\/pre>\n<h5>FunSuite<\/h5>\n<p>  FunSuite \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d \u0434\u043b\u044f \u043a\u043e\u043c\u0430\u043d\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0440\u0430\u043d\u0435\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438 xUnit, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u044d\u0442\u043e\u0433\u043e \u0441\u0442\u0438\u043b\u044f \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043a\u043e\u043c\u0444\u043e\u0440\u0442\u043d\u043e \u043f\u0435\u0440\u0435\u0439\u0442\u0438 \u043d\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 Scalatest \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432\u0430 BDD. \u041f\u0440\u0438\u043c\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f:  <\/p>\n<pre><code class=\"scala\">import org.scalatest.FunSuite  class SetSuite extends FunSuite {    test(&quot;An empty Set should have size 0&quot;) {     assert(Set.empty.size == 0)   }    test(&quot;Invoking head on an empty Set should produce NoSuchElementException&quot;) {     intercept[NoSuchElementException] {       Set.empty.head     }   } } <\/code><\/pre>\n<h5>FunSpec<\/h5>\n<p>  FunSpec \u0430\u0432\u0442\u043e\u0440\u044b Scalatest \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u044e\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u0435\u043c, \u043a\u0442\u043e \u0440\u0430\u043d\u0435\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b \u0432\u0440\u043e\u0434\u0435 RSpec \u0434\u043b\u044f Ruby  <\/p>\n<pre><code class=\"scala\">import org.scalatest.FunSpec  class SetSpec extends FunSpec {    describe(&quot;A Set&quot;) {     describe(&quot;when empty&quot;) {       it(&quot;should have size 0&quot;) {         assert(Set.empty.size == 0)       }        it(&quot;should produce NoSuchElementException when head is invoked&quot;) {         intercept[NoSuchElementException] {           Set.empty.head         }       }     }   } } <\/code><\/pre>\n<h5>WordSpec<\/h5>\n<p>  \u0422\u0430\u043a \u0436\u0435, \u0434\u043b\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 specs \u0438 specs2 \u0430\u0432\u0442\u043e\u0440\u044b scalatest \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u044e\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u0440\u0435\u0439\u0442 WordSpec, \u043a\u043e\u0442\u043e\u0440\u044b\u0439, \u043f\u043e \u0438\u0445 \u0443\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u044e, \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0435\u0441\u0442\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c \u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0442\u0435\u0441\u0442\u044b \u0441\u043e specs \u043d\u0430 scalatest.  <\/p>\n<pre><code class=\"scala\">import org.scalatest.WordSpec  class SetSpec extends WordSpec {    &quot;A Set&quot; when {     &quot;empty&quot; should {       &quot;have size 0&quot; in {         assert(Set.empty.size == 0)       }        &quot;produce NoSuchElementException when head is invoked&quot; in {         intercept[NoSuchElementException] {           Set.empty.head         }       }     }   } } <\/code><\/pre>\n<p>  \u0417\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0442\u0435\u0441\u0442\u0430 \u0432\u043e FlatSpec \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u0435\u043c, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442 \u0442\u0435\u0441\u0442\u0438\u0440\u0443\u0435\u043c\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0438 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 \u043f\u043e\u0434\u043b\u0435\u0436\u0430\u0449\u0435\u0433\u043e, \u043a\u043b\u044e\u0447\u0435\u0432\u043e\u0433\u043e \u0441\u043b\u043e\u0432\u0430 should must \u0438\u043b\u0438 can \u0438 \u043a\u043e\u043d\u0446\u0430 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u044f. \u043f\u043e\u0441\u043b\u0435 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0430 \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0441\u043b\u043e\u0432\u043e in \u0438 \u0441\u0430\u043c\u043e \u0442\u0435\u043b\u043e \u0442\u0435\u0441\u0442\u0430 \u0432 \u0444\u0438\u0433\u0443\u0440\u043d\u044b\u0445 \u0441\u043a\u043e\u0431\u043a\u0430\u0445. \u0412\u043e\u0442 \u0437\u0430\u043a\u043e\u043d\u0447\u0435\u043d\u043d\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u0442\u0435\u0441\u0442\u0430:<\/p>\n<pre><code class=\"scala\">import collection.mutable.Stack import org.scalatest._  class StackSpec extends FlatSpec {    &quot;A Stack&quot; should &quot;pop values in last-in-first-out order&quot; in {     val stack = new Stack[Int]     stack.push(1)     stack.push(2)     assert(stack.pop() == 2)     assert(stack.pop() == 1)   }    it should &quot;throw NoSuchElementException if an empty stack is popped&quot; in {     val emptyStack = new Stack[String]     intercept[NoSuchElementException] {       emptyStack.pop()     }   } } <\/code><\/pre>\n<h5>Assertions<\/h5>\n<p>  \u0412 \u043a\u0430\u0436\u0434\u043e\u043c \u0441\u0442\u0438\u043b\u0435 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u043e 3 \u0430\u0441\u0441\u0435\u0440\u0442\u0430:<\/p>\n<ul>\n<li>assert \u0434\u043b\u044f \u043e\u0431\u044b\u0447\u043d\u044b\u0445 \u043f\u0440\u043e\u0432\u0435\u0440\u043e\u043a<\/li>\n<li>assertResult \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0441\u043e\u0432\u043f\u0430\u0434\u0435\u043d\u0438\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u043e\u0433\u043e \u0438 \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u043e\u0433\u043e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430<\/li>\n<li>intercept \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u043c\u0435\u0442\u043e\u0434 \u0431\u0440\u043e\u0441\u0430\u0435\u0442 \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u043e\u0435 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/li>\n<\/ul>\n<p>  Scalatest \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u0441\u0432\u043e\u0439 \u043c\u0435\u0442\u043e\u0434 assert, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043a\u0440\u044b\u0432\u0430\u0435\u0442 \u043c\u0435\u0442\u043e\u0434, \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0439 \u0432 predef \u0438 \u0431\u0440\u043e\u0441\u0430\u0435\u0442 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 TestFailedException \u0432\u043c\u0435\u0441\u0442\u043e \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0433\u043e AssertionError. \u0422\u0435\u043c \u043d\u0435 \u043c\u0435\u043d\u0435\u0435, \u043c\u0435\u0442\u043e\u0434 assert \u043d\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u0440\u043e\u0432\u0435\u0441\u0442\u0438 \u0440\u0430\u0437\u043b\u0438\u0447\u0438\u0435 \u043c\u0435\u0436\u0434\u0443 \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u044b\u043c \u0438 \u0444\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u043c. \u042d\u0442\u043e \u0440\u0430\u0437\u043b\u0438\u0447\u0438\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0432\u0435\u0441\u0442\u0438 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043c\u0435\u0442\u043e\u0434\u0430 assertResult:  <\/p>\n<pre><code class=\"scala\">val a = 5 val b = 2 assertResult(2) {   a - b } <\/code><\/pre>\n<p>  \u0432 \u0442\u0430\u043a\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u0435\u0441\u043b\u0438 \u0444\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043d\u0435 \u0441\u043e\u0432\u043f\u0430\u0434\u0435\u0442 \u0441 \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u044b\u043c, \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u0432 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0438 TestFailedException \u0431\u0443\u0434\u0435\u0442 \u00abExpected 2, but got 3.\u00bb.<br \/>  \u041c\u0435\u0442\u043e\u0434 intercept \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u044b\u0435 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f:  <\/p>\n<pre><code class=\"scala\">val s = &quot;hi&quot; intercept[IndexOutOfBoundsException] {   s.charAt(-1) } <\/code><\/pre>\n<p>  \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443, \u043e\u043d \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0442\u043e \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043f\u043e\u0439\u043c\u0430\u043b, \u0435\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0442\u0430\u043a \u0436\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u0438\u043b\u0438 \u0434\u0440\u0443\u0433\u043e\u0439 \u043c\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438, \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u043d\u043e\u0439 \u043a \u044d\u0442\u043e\u043c\u0443 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044e:  <\/p>\n<pre><code class=\"scala\">intercept[IndexOutOfBoundsException](s charAt -1).getMessage should be == &quot;...&quot; <\/code><\/pre>\n<h5>Matchers<\/h5>\n<p>  \u0412 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043c\u0435\u0442\u0438\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0441\u043b\u043e\u0432\u0430 be. \u0412 scalatest \u044d\u0442\u043e \u2014 \u0442\u043e\u0436\u0435 \u043e\u0434\u043d\u043e \u0438\u0437 \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u0445 \u0441\u043b\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c, \u0435\u0441\u043b\u0438 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u043c\u0438\u043a\u0441\u0438\u043d Matchers \u0432 \u043a\u043b\u0430\u0441\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442 \u0442\u0435\u0441\u0442. \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443, scalatest \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u0447\u0435\u043d\u044c \u043f\u0440\u0438\u0431\u043b\u0438\u0436\u0435\u043d\u043d\u044b\u043c \u043a \u0435\u0441\u0442\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u043c\u0443 \u044f\u0437\u044b\u043a\u0443 DSL, \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0438\u0439 \u043a\u043e\u0434 \u043f\u043e\u0434 \u044d\u0442\u0438\u043c \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u043e\u043c \u0434\u0430\u0451\u0442\u0441\u044f \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0431\u0435\u0437 \u043f\u043e\u044f\u0441\u043d\u0435\u043d\u0438\u0439.<\/p>\n<p>  \u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u044d\u0442\u043e\u0433\u043e \u0442\u0440\u0435\u0439\u0442\u0430, \u043c\u043e\u0436\u043d\u043e \u043f\u0438\u0441\u0430\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u043f\u0440\u0438\u0431\u043b\u0438\u0436\u0435\u043d\u043d\u044b\u0435 \u043a \u0435\u0441\u0442\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u043c\u0443 \u044f\u0437\u044b\u043a\u0443 \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438:  <\/p>\n<h6>\u0420\u0430\u0432\u0435\u043d\u0441\u0442\u0432\u043e<\/h6>\n<p>  <\/p>\n<pre><code class=\"scala\">4 must equal(4) &quot;foo&quot; must equal(&quot;foo&quot;) List(&quot;foo&quot;, &quot;bar&quot;, &quot;baz&quot;) must equal(List(&quot;foo&quot;, &quot;bar&quot;, &quot;baz&quot;)) (1, &quot;foo&quot;) must equal((1, &quot;foo&quot;))  <\/code><\/pre>\n<p>  <\/p>\n<h6>\u0420\u0430\u0437\u043c\u0435\u0440 \u043e\u0431\u044a\u0435\u043a\u0442\u0430, \u0434\u043b\u0438\u043d\u0430 \u043e\u0431\u044a\u0435\u043a\u0442\u0430<\/h6>\n<p>  <\/p>\n<pre><code class=\"scala\">&quot;foo&quot; must have length (3) List(1, 2, 3, 4) must have length (4) Array('A', 'B') must have length (2)  List(1, 2, 3, 4) must have size (4) Array('A', 'B') must have size (2)  <\/code><\/pre>\n<p>  <\/p>\n<h5>\u041f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0441\u0442\u0440\u043e\u043a<\/h5>\n<p>  <\/p>\n<pre><code class=\"scala\">&quot;foobarbaz&quot; must startWith(&quot;foo&quot;) &quot;foobarbaz&quot; must endWith(&quot;baz&quot;) &quot;foobarbaz&quot; must include(&quot;bar&quot;)  &quot;foobarbaz&quot; must startWith regex (&quot;f[o]+&quot;) &quot;foobarbaz&quot; must endWith regex (&quot;[ba]{2}z&quot;) &quot;foobarbaz&quot; must include regex (&quot;foo[\\\\w]{3}baz&quot;) &quot;foobarbaz&quot; must fullyMatch regex (&quot;\\\\w{1}oobarbaz&quot;)  <\/code><\/pre>\n<p>  <\/p>\n<h6>\u041f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0447\u0438\u0441\u0435\u043b<\/h6>\n<p>  <\/p>\n<pre><code class=\"scala\">7 must be &lt; (8) 7 must be &gt; (0) 6 must be &lt;= (7) 7 must be &gt;= (6) 13.43 must equal(13.43) 13.43 must be(13.4 plusOrMinus 0.4)  <\/code><\/pre>\n<p>  <\/p>\n<h6>\u041f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0431\u0443\u043b\u0435\u0432\u044b\u0445 \u0441\u0432\u043e\u0439\u0441\u0442\u0432<\/h6>\n<p>  <\/p>\n<pre><code class=\"scala\">List[Int]() must be('empty) \/\/ \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 list.isEmpty new File(&quot;\/tmp&quot;) must be('directory) \/\/ \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 file.isDirectory  <\/code><\/pre>\n<p>  <\/p>\n<h6>\u041a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438<\/h6>\n<p>  <\/p>\n<pre><code class=\"scala\">List(1, 2, 3, 4) must contain(2) Array(&quot;foo&quot;, &quot;bar&quot;, &quot;baz&quot;) must contain(&quot;bar&quot;) var users = Map(1 -&gt; &quot;Joe&quot;, 2 -&gt; &quot;Lisa&quot;, 3 -&gt; &quot;Dr. Evil&quot;) users must contain key (2) users must contain value (&quot;Dr. Evil&quot;)  <\/code><\/pre>\n<p>  <\/p>\n<h6>\u0421\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u043a\u043b\u0430\u0441\u0441\u0430<\/h6>\n<p>  <\/p>\n<pre><code class=\"scala\">case class Recipe(name: String, ingredients: List[String], bakingMinutes: Int)  val cookieRecipe = Recipe(&quot;cookieRecipe&quot;, List(&quot;Flour&quot;, &quot;Sugar&quot;, &quot;Eggs&quot;, &quot;Love&quot;), 30) cookieRecipe must have( 'name(&quot;cookieRecipe&quot;), 'ingredients(List(&quot;Flour&quot;, &quot;Sugar&quot;, &quot;Eggs&quot;, &quot;Love&quot;)), 'bakingMinutes(30) )  <\/code><\/pre>\n<p>  <\/p>\n<h6>\u0421\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u043e\u043a \u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u0438\u043c\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u043c\u0438<\/h6>\n<p>  \u0422\u0430\u043a \u0436\u0435, \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u043c\u043e\u0436\u043d\u043e \u0441\u043e\u0435\u0434\u0438\u043d\u044f\u0442\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 and\/or, \u043d\u043e \u0432\u0430\u0436\u043d\u043e \u043d\u0435 \u0437\u0430\u0431\u044b\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u043a\u043e\u0431\u043a\u0438, \u0442\u0430\u043a \u043f\u0440\u0438\u043c\u0435\u0440 users must have size(3) and contain key(3) \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e.  <\/p>\n<pre><code class=\"scala\">users must (have size (3) and contain key (3)) users must (contain value (&quot;Mr. X&quot;) or contain value (&quot;Joe&quot;))<\/code><\/pre>\n<p>  \u0412 \u0441\u0442\u0430\u0442\u044c\u0435 \u043d\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u043e \u0435\u0449\u0435 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0435\u0439 \u044d\u0442\u043e\u0433\u043e \u0437\u0430\u043c\u0435\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0430, \u0442\u0430\u043a\u0438\u0445 \u043a\u0430\u043a \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 mock-\u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0438\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 Selenium, \u043e\u0434\u043d\u0430\u043a\u043e \u0434\u0430\u0436\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0445 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0435\u0439 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u0438\u0441\u0430\u0442\u044c \u043a\u0440\u0430\u0441\u0438\u0432\u044b\u0435 \u0438 \u043b\u0435\u0433\u043a\u0438\u0435 \u0434\u043b\u044f \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u044f \u0442\u0435\u0441\u0442\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u043b\u0435\u0433\u043a\u043e \u0447\u0438\u0442\u0430\u0435\u043c\u044b \u0438 \u0442\u0435\u0441\u0442\u044b, \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u043f\u0440\u0438\u0431\u043b\u0438\u0436\u0435\u043d\u043d\u044b\u0435 \u043f\u043e \u0441\u0442\u0435\u043f\u0435\u043d\u0438 \u0432\u044b\u0440\u0430\u0437\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u043a \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u043a\u043e\u0434\u0430.<\/p>\n<hr\/>\n<p>  <a href=\"http:\/\/www.scalatest.org\/\">www.scalatest.org\/<\/a> \u2014 \u0441\u0430\u0439\u0442 \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \t\t\t<\/p>\n<div class=\"clear\"><\/div>\n<\/p><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/209578\/\"> http:\/\/habrahabr.ru\/post\/209578\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\"> \t\t\tScalatest \u2014 \u044d\u0442\u043e \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a \u0434\u043b\u044f \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439, \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u044e\u0449\u0438\u0439 \u0440\u0430\u0437\u043d\u044b\u0435 \u0441\u0442\u0438\u043b\u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0442\u0435\u0441\u0442\u043e\u0432 \u0438 \u043b\u0435\u0433\u043a\u043e \u0438\u043d\u0442\u0435\u0433\u0440\u0438\u0440\u0443\u044e\u0449\u0438\u0439\u0441\u044f \u0441 \u0434\u0440\u0443\u0433\u0438\u043c\u0438 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u0430\u043c\u0438 \u0434\u043b\u044f JVM, \u0432\u043a\u043b\u044e\u0447\u0430\u044f IDE \u0438 maven.  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-209578","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/209578","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=209578"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/209578\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=209578"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=209578"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=209578"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}