You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
1. Перезапустите тест `CubeCalculatorTest`, кликнув правой кнопкой мыши и выбрав
68
68
**Run 'CubeCalculatorTest'**.
69
69
70
-
## Резюме
70
+
## Заключение
71
71
Вы видели один из способов тестирования Scala кода.
72
-
Узнать больше о FunSuite от ScalaTest можно на [официальном сайте](https://www.scalatest.org/getting_started_with_fun_suite).
72
+
Узнать больше о AnyFunSuite от ScalaTest можно на [официальном сайте](https://www.scalatest.org/getting_started_with_fun_suite).
73
+
Вы также можете использовать другие тестовые фреймворки, такие как [ScalaCheck](https://www.scalacheck.org/) и [Specs2](https://etorreborre.github.io/specs2/).
There are multiple libraries and testing methodologies for Scala,
11
-
but in this tutorial, we'll demonstrate one popular option from the ScalaTest framework
12
-
called [AnyFunSuite](https://www.scalatest.org/scaladoc/3.2.2/org/scalatest/funsuite/AnyFunSuite.html).
13
-
We assume you know [how to create a Scala project with sbt](getting-started-with-scala-and-sbt-on-the-command-line.html).
10
+
Для Scala существует множество библиотек и методологий тестирования,
11
+
но в этом руководстве мы продемонстрируем один популярный вариант из фреймворка ScalaTest
12
+
под названием [AnyFunSuite](https://www.scalatest.org/getting_started_with_fun_suite).
14
13
15
-
## Setup
16
-
1. On the command line, create a new directory somewhere.
17
-
1.`cd` into the directory and run `sbt new scala/scalatest-example.g8`
18
-
1. Name the project `ScalaTestTutorial`.
19
-
1. The project comes with ScalaTest as a dependency in the `build.sbt` file.
20
-
1.`cd` into the directory and run `sbt test`. This will run the test suite
21
-
`CubeCalculatorTest` with a single test called `CubeCalculator.cube`.
14
+
Это предполагает, что вы знаете, [как создать проект с sbt](getting-started-with-scala-and-sbt-on-the-command-line.html).
15
+
16
+
## Настройка
17
+
1. Используя командную строку создайте новую директорию.
18
+
1. Перейдите (`cd`) в этот каталог и запустите `sbt new scala/scalatest-example.g8`.
19
+
1. Назовите проект `ScalaTestTutorial`.
20
+
1. Проект поставляется с зависимостью ScalaTest в файле `build.sbt`.
21
+
1. Перейдите (`cd`) в этот каталог и запустите `sbt test`. Это запустит набор тестов
22
+
`CubeCalculatorTest` с одним тестом под названием `CubeCalculator.cube`.
22
23
23
24
```
24
25
sbt test
@@ -35,39 +36,35 @@ sbt test
35
36
[success] Total time: 1 s, completed Feb 2, 2017 7:37:31 PM
36
37
```
37
38
38
-
## Understanding tests
39
-
1.Open up two files in a text editor:
39
+
## Разбор кода
40
+
1.Откройте два файла в текстовом редакторе:
40
41
*`src/main/scala/CubeCalculator.scala`
41
42
*`src/test/scala/CubeCalculatorTest.scala`
42
-
1. In the file `CubeCalculator.scala`, you'll see how we define the function `cube`.
43
-
1. In the file `CubeCalculatorTest.scala`, you'll see that we have a class
44
-
named after the object we're testing.
43
+
1. В файле `CubeCalculator.scala` увидите определение функции `cube`.
44
+
1. В файле `CubeCalculatorTest.scala` тестируемый класс, названный так же как и объект.
45
45
46
46
```
47
47
import org.scalatest.funsuite.AnyFunSuite
48
48
49
-
class CubeCalculatorTest extends AnyFunSuite {
49
+
class CubeCalculatorTest extends AnyFunSuite:
50
50
test("CubeCalculator.cube") {
51
51
assert(CubeCalculator.cube(3) === 27)
52
52
}
53
-
}
54
53
```
55
54
56
-
Let's go over this line by line.
55
+
Давайте разберем код построчно:
57
56
58
-
*`class CubeCalculatorTest` means we are testing the object `CubeCalculator`
59
-
*`extends AnyFunSuite` lets us use functionality of ScalaTest's AnyFunSuite class
60
-
such as the `test` function
61
-
*`test` is function that comes from AnyFunSuite that collects
62
-
results from assertions within the function body.
63
-
*`"CubeCalculator.cube"` is a name for the test. You can call it anything but
64
-
one convention is "ClassName.methodName".
65
-
*`assert` takes a boolean condition and determines whether the test passes or fails.
66
-
*`CubeCalculator.cube(3) === 27` checks whether the output of the `cube` function is
67
-
indeed 27. The `===` is part of ScalaTest and provides clean error messages.
57
+
*`class CubeCalculatorTest` означает, что мы тестируем `CubeCalculator`
58
+
*`extends AnyFunSuite` позволяет нам использовать функциональность класса AnyFunSuite из ScalaTest,
59
+
такую как функция `test`
60
+
*`test` это функция из библиотеки FunSuite, которая собирает результаты проверок в теле функции.
61
+
*`"CubeCalculator.cube"` - это имя для теста. Вы можете называть тест как угодно, но по соглашению используется имя — "ClassName.methodName".
62
+
*`assert` принимает логическое условие и определяет, пройден тест или нет.
63
+
*`CubeCalculator.cube(3) === 27` проверяет, действительно ли вывод функции `cube` равен 27.
64
+
`===` является частью ScalaTest и предоставляет понятные сообщения об ошибках.
68
65
69
-
## Adding another test case
70
-
1.Add another test block with its own `assert` statement that checks for the cube of `0`.
66
+
## Добавление еще одного теста
67
+
1.Добавьте еще один тестовый блок с собственным оператором assert, который проверяет 0 в кубе.
71
68
72
69
```
73
70
import org.scalatest.funsuite.AnyFunSuite
@@ -83,7 +80,7 @@ indeed 27. The `===` is part of ScalaTest and provides clean error messages.
83
80
}
84
81
```
85
82
86
-
1. Execute `sbt test` again to see the results.
83
+
1. Запустите `sbt test` еще раз, чтобы увидеть результаты.
87
84
88
85
```
89
86
sbt test
@@ -102,6 +99,7 @@ indeed 27. The `===` is part of ScalaTest and provides clean error messages.
102
99
[success] Total time: 3 s, completed Dec 4, 2019 10:34:04 PM
103
100
```
104
101
105
-
## Conclusion
106
-
You've seen one way to test your Scala code. You can learn more about
107
-
ScalaTest's FunSuite on the [official website](https://www.scalatest.org/getting_started_with_fun_suite). You can also check out other testing frameworks such as [ScalaCheck](https://www.scalacheck.org/) and [Specs2](https://etorreborre.github.io/specs2/).
102
+
## Заключение
103
+
Вы видели один из способов тестирования Scala кода.
104
+
Узнать больше о AnyFunSuite от ScalaTest можно на [официальном сайте](https://www.scalatest.org/getting_started_with_fun_suite).
105
+
Вы также можете использовать другие тестовые фреймворки, такие как [ScalaCheck](https://www.scalacheck.org/) и [Specs2](https://etorreborre.github.io/specs2/).
0 commit comments