From 66018e4d1defcc9109af81105ec5784f0538d33e Mon Sep 17 00:00:00 2001 From: Nathaniel Nutter Date: Sat, 21 Apr 2018 19:54:51 -0500 Subject: [PATCH 1/7] indent code blocks to improve style This indents the code blocks associated with a given list item so that they are continuations of the list items. --- ...esting-scala-in-intellij-with-scalatest.md | 43 +++++++++---------- 1 file changed, 20 insertions(+), 23 deletions(-) diff --git a/getting-started-intellij-track/testing-scala-in-intellij-with-scalatest.md b/getting-started-intellij-track/testing-scala-in-intellij-with-scalatest.md index cfd5b70fe5..15d174e7f2 100644 --- a/getting-started-intellij-track/testing-scala-in-intellij-with-scalatest.md +++ b/getting-started-intellij-track/testing-scala-in-intellij-with-scalatest.md @@ -12,11 +12,10 @@ We assume you know [how to build a project in IntelliJ](building-a-scala-project ## Setup 1. Create an sbt project in IntelliJ. -* Add the ScalaTest dependency to your build.sbt file: - -``` -libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.5" % "test" -``` +* Add the ScalaTest dependency to your build.sbt file + ``` + libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.5" % "test" + ``` 1. this will cause sbt to pull down the ScalaTest library 1. If you get a notification "build.sbt was changed", select **auto-import**. @@ -24,30 +23,28 @@ libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.5" % "test" 1. Right-click on `scala` and select **New** => **Scala class**. 1. Call it `CubeCalculator`, change the **Kind** to `object`, and click **OK**. 1. Replace the code with the following: - -``` -object CubeCalculator extends App { - def cube(x: Int) = { - x * x * x - } -} -``` + ``` + object CubeCalculator extends App { + def cube(x: Int) = { + x * x * x + } + } + ``` ## Creating a test 1. On the project pane on the left, expand `src` => `test`. 1. Right-click on `scala` and select **New** => **Scala class**. 1. Name the class `CubeCalculatorTest` and click **OK**. 1. Replace the code with the following: - -``` -import org.scalatest.FunSuite - -class CubeCalculatorTest extends FunSuite { - test("CubeCalculator.cube") { - assert(CubeCalculator.cube(3) === 27) - } -} -``` + ``` + import org.scalatest.FunSuite + + class CubeCalculatorTest extends FunSuite { + test("CubeCalculator.cube") { + assert(CubeCalculator.cube(3) === 27) + } + } + ``` 1. In the source code, right-click `CubeCalculatorTest` and select **Run 'CubeCalculatorTest'**. From a92b0a3dc343cb53cd8382c413959868c9851b63 Mon Sep 17 00:00:00 2001 From: Nathaniel Nutter Date: Sat, 21 Apr 2018 20:02:33 -0500 Subject: [PATCH 2/7] fix list ordering to improve style This converts this list item to a ordered item so that the ordered list is not broken by the unordered list item. --- .../testing-scala-in-intellij-with-scalatest.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/getting-started-intellij-track/testing-scala-in-intellij-with-scalatest.md b/getting-started-intellij-track/testing-scala-in-intellij-with-scalatest.md index 15d174e7f2..669f0c1e58 100644 --- a/getting-started-intellij-track/testing-scala-in-intellij-with-scalatest.md +++ b/getting-started-intellij-track/testing-scala-in-intellij-with-scalatest.md @@ -12,11 +12,10 @@ We assume you know [how to build a project in IntelliJ](building-a-scala-project ## Setup 1. Create an sbt project in IntelliJ. -* Add the ScalaTest dependency to your build.sbt file +1. Add the ScalaTest dependency to your build.sbt file ``` libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.5" % "test" ``` - 1. this will cause sbt to pull down the ScalaTest library 1. If you get a notification "build.sbt was changed", select **auto-import**. 1. On the project pane on the left, expand `src` => `main`. @@ -45,7 +44,6 @@ We assume you know [how to build a project in IntelliJ](building-a-scala-project } } ``` - 1. In the source code, right-click `CubeCalculatorTest` and select **Run 'CubeCalculatorTest'**. From f0404262371ec1197888f61e22feeabfe370b548 Mon Sep 17 00:00:00 2001 From: Nathaniel Nutter Date: Sat, 21 Apr 2018 20:14:10 -0500 Subject: [PATCH 3/7] group list items related to ScalaTest dependency This groups the list items related to adding the ScalaTest dependency to improve readability. --- .../testing-scala-in-intellij-with-scalatest.md | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/getting-started-intellij-track/testing-scala-in-intellij-with-scalatest.md b/getting-started-intellij-track/testing-scala-in-intellij-with-scalatest.md index 669f0c1e58..099c0c2c1c 100644 --- a/getting-started-intellij-track/testing-scala-in-intellij-with-scalatest.md +++ b/getting-started-intellij-track/testing-scala-in-intellij-with-scalatest.md @@ -12,12 +12,13 @@ We assume you know [how to build a project in IntelliJ](building-a-scala-project ## Setup 1. Create an sbt project in IntelliJ. -1. Add the ScalaTest dependency to your build.sbt file - ``` - libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.5" % "test" - ``` -1. this will cause sbt to pull down the ScalaTest library -1. If you get a notification "build.sbt was changed", select **auto-import**. +1. Add the ScalaTest dependency: + 1. Add the ScalaTest dependency to your `build.sbt` file: + ``` + libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.5" % "test" + ``` + 1. If you get a notification "build.sbt was changed", select **auto-import**. + 1. These two actions will cause `sbt` to download the ScalaTest library. 1. On the project pane on the left, expand `src` => `main`. 1. Right-click on `scala` and select **New** => **Scala class**. 1. Call it `CubeCalculator`, change the **Kind** to `object`, and click **OK**. @@ -49,7 +50,7 @@ We assume you know [how to build a project in IntelliJ](building-a-scala-project ## Understanding the code -Let's go over this line by line. +Let's go over this line by line: * `class CubeCalculatorTest` means we are testing the object `CubeCalculator` * `extends FunSuite` lets us use functionality of ScalaTest's FunSuite class From b50af1c2b567d6a52cfd885f08e95fc73dfe1682 Mon Sep 17 00:00:00 2001 From: Nathaniel Nutter Date: Sat, 21 Apr 2018 20:18:14 -0500 Subject: [PATCH 4/7] grammar change Rather than personifying the document or referring to the author(s) just state that the tutorial assumes prior knowledge. --- .../testing-scala-in-intellij-with-scalatest.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/getting-started-intellij-track/testing-scala-in-intellij-with-scalatest.md b/getting-started-intellij-track/testing-scala-in-intellij-with-scalatest.md index 099c0c2c1c..66bdbbbf55 100644 --- a/getting-started-intellij-track/testing-scala-in-intellij-with-scalatest.md +++ b/getting-started-intellij-track/testing-scala-in-intellij-with-scalatest.md @@ -8,7 +8,8 @@ previous-page: building-a-scala-project-with-intellij-and-sbt There are multiple libraries and testing methodologies for Scala, but in this tutorial, we'll demonstrate one popular option from the ScalaTest framework called [FunSuite](http://www.scalatest.org/getting_started_with_fun_suite). -We assume you know [how to build a project in IntelliJ](building-a-scala-project-with-intellij-and-sbt.html). + +This assumes you know [how to build a project in IntelliJ](building-a-scala-project-with-intellij-and-sbt.html). ## Setup 1. Create an sbt project in IntelliJ. From ddaba5c84db32129529de9bd6eb0261de88c6f53 Mon Sep 17 00:00:00 2001 From: Nathaniel Nutter Date: Sat, 21 Apr 2018 20:18:54 -0500 Subject: [PATCH 5/7] rewrap a few lines This rewraps a few lines to improve readability. --- .../testing-scala-in-intellij-with-scalatest.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/getting-started-intellij-track/testing-scala-in-intellij-with-scalatest.md b/getting-started-intellij-track/testing-scala-in-intellij-with-scalatest.md index 66bdbbbf55..fe61e5774c 100644 --- a/getting-started-intellij-track/testing-scala-in-intellij-with-scalatest.md +++ b/getting-started-intellij-track/testing-scala-in-intellij-with-scalatest.md @@ -46,8 +46,8 @@ This assumes you know [how to build a project in IntelliJ](building-a-scala-proj } } ``` -1. In the source code, right-click `CubeCalculatorTest` and select **Run -'CubeCalculatorTest'**. +1. In the source code, right-click `CubeCalculatorTest` and select + **Run 'CubeCalculatorTest'**. ## Understanding the code @@ -66,10 +66,10 @@ indeed 27. The `===` is part of ScalaTest and provides clean error messages. ## Adding another test case 1. Add another `assert` statement after the first one that checks for the cube -of `0`. + of `0`. 1. Re-run the test again by right-clicking `CubeCalculatorTest` and selecting -'Run **CubeCalculatorTest**'. + 'Run **CubeCalculatorTest**'. ## Conclusion -You've seen one way to test your Scala code. You can learn more about -ScalaTest's FunSuite on the [official website](http://www.scalatest.org/getting_started_with_fun_suite). +You've seen one way to test your Scala code. You can learn more about ScalaTest's +FunSuite on the [official website](http://www.scalatest.org/getting_started_with_fun_suite). From 0a45f6c29fa915ca818548dfbaf77077a651a674 Mon Sep 17 00:00:00 2001 From: Nathaniel Nutter Date: Sat, 21 Apr 2018 20:20:33 -0500 Subject: [PATCH 6/7] add "build project" step For me, after `sbt` downloads ScalaTest the `CubeCalculatorTest` class will still have several errors because ScalaTest has not been compiled/indexed by IntelliJ IDEA so this explicitly adds a "build project" step to trigger that. --- .../testing-scala-in-intellij-with-scalatest.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/getting-started-intellij-track/testing-scala-in-intellij-with-scalatest.md b/getting-started-intellij-track/testing-scala-in-intellij-with-scalatest.md index fe61e5774c..54b912f428 100644 --- a/getting-started-intellij-track/testing-scala-in-intellij-with-scalatest.md +++ b/getting-started-intellij-track/testing-scala-in-intellij-with-scalatest.md @@ -20,6 +20,8 @@ This assumes you know [how to build a project in IntelliJ](building-a-scala-proj ``` 1. If you get a notification "build.sbt was changed", select **auto-import**. 1. These two actions will cause `sbt` to download the ScalaTest library. + 1. Build the project to compile/index the ScalaTest library by selecting the + **Build** menu and then **Build Project**. 1. On the project pane on the left, expand `src` => `main`. 1. Right-click on `scala` and select **New** => **Scala class**. 1. Call it `CubeCalculator`, change the **Kind** to `object`, and click **OK**. From c2f15f5d621634eeeb288874dda994ba15b7237e Mon Sep 17 00:00:00 2001 From: Nathaniel Nutter Date: Tue, 24 Apr 2018 20:55:44 -0500 Subject: [PATCH 7/7] correctly identify cause of FunSuite and test() not being recognized When I followed this tutorial I either did it really fast or in the wrong order and ended up with `FunSuite` and `test()` not being recognized. I mistakenly thought building the project fixed it but it turns out I just didn't notice that `sbt` hadn't finished syncing. --- .../testing-scala-in-intellij-with-scalatest.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/getting-started-intellij-track/testing-scala-in-intellij-with-scalatest.md b/getting-started-intellij-track/testing-scala-in-intellij-with-scalatest.md index 54b912f428..93a9574272 100644 --- a/getting-started-intellij-track/testing-scala-in-intellij-with-scalatest.md +++ b/getting-started-intellij-track/testing-scala-in-intellij-with-scalatest.md @@ -20,8 +20,8 @@ This assumes you know [how to build a project in IntelliJ](building-a-scala-proj ``` 1. If you get a notification "build.sbt was changed", select **auto-import**. 1. These two actions will cause `sbt` to download the ScalaTest library. - 1. Build the project to compile/index the ScalaTest library by selecting the - **Build** menu and then **Build Project**. + 1. Wait for the `sbt` sync to finish; otherwise, `FunSuite` and `test()` will be + unrecognized. 1. On the project pane on the left, expand `src` => `main`. 1. Right-click on `scala` and select **New** => **Scala class**. 1. Call it `CubeCalculator`, change the **Kind** to `object`, and click **OK**.