From 3ba7bd87766b0826709d6d100627597f28d6baa8 Mon Sep 17 00:00:00 2001 From: Craig Date: Sun, 23 Jun 2019 20:37:59 +0100 Subject: [PATCH] create Console and Library Tests Overview page. --- Console-and-Library-Tests-Overview.md | 42 +++++++++++++++++++++++++++ Home.md | 2 +- _sidebar.md | 2 +- 3 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 Console-and-Library-Tests-Overview.md diff --git a/Console-and-Library-Tests-Overview.md b/Console-and-Library-Tests-Overview.md new file mode 100644 index 0000000..eaeaeff --- /dev/null +++ b/Console-and-Library-Tests-Overview.md @@ -0,0 +1,42 @@ +Instead of going through both of the main testing files (I.E. "ConsoleTests.fs" and "LibraryTests.fs"), I will provide an overview of how they work. If you want to make your way through the source code you can do so by using the following links; + +- [ConsoleTests.fs](https://gitlab.com/craig.oates/Death-Socket/blob/master/TestCentre/ConsoleTests.fs) +- [LibraryTests.fs](https://gitlab.com/craig.oates/Death-Socket/blob/master/TestCentre/LibraryTests.fs) + +The general structure for each file is the same. Each one has a module called `PropertyTests` with "helper" functions at the top of them. It is worth pointing out both of these modules live in name-spaces. This is what allows both "testing" files to use the same module name. If you are wondering why I did it this way, it is because it makes it easier to read the Test Explorer (in Visual Studio). For now, the only unit tests you will see are in "ConsoleTests.fs", residing in the `UnitTests` module. + +IMAGE OF TEST EXPLORER. + +As an aside, I have kept the "helper" functions next to the actual tests for a reason: to avoid "over-engineering". It seemed a little excessive to "modularise" everything with such a small amount of tests. Although, I admit this approach will need to change if the repository grows in the future. If/when that time comes, TestCentre will need refactoring. Keep this in mind if you decide to add your own changes/features. + +TEST FILE BREAKDOWN. + +One way to denote a property test from a unit test is by looking at their attributes. If a test has `[]` next to it, it is a property test. If a test has `[]` next to it, it is a unit test. For example, + +```f# +// This is a unit test -- uses xUnit. +[] + let ``Colour map is not empty`` () = + Assert.NotEmpty colourList + +// This is a property test -- uses FsCheck. +[] +let ``Can create an image with a full overlay`` () = + resetSavingTestArea () + let spec = + { width = randomInt () + height = randomInt () + colour = randomColour () :?> Brush + filePath = saveLocation + overlay = Some (buildFullOverlay ()) } + makeImage spec |> Async.RunSynchronously + fileSaved (spec.width.ToString()) (spec.height.ToString()) = true +``` + +As stated in other parts of this wiki, make sure you have a folder called "SavingTestArea" within TestCentre. If you do not have this folder on your machine, a lot of the tests will fail. This is because TestCentre uses it as a place to save and check the images it creates. To help you check, here is what your TestCentre project should look like: + +IMAGE OF FILE STRUCTURE IN TESTCENTRE. + +The easiest way to add this folder to TestCentre is by right-clicking on "TestCentre" in Visual Studio's Solution Explorer. From there, head to _Add -> New Folder_. Having said that, you can add the "SavingTestArea" folder to TestCentre with File Explorer if you want. This is because Visual Studio does not need to know it exists. You just need it on your machine. + +SCREENSHOT OF ADDING A NEW FOLDER. diff --git a/Home.md b/Home.md index 1119524..a7c872e 100644 --- a/Home.md +++ b/Home.md @@ -63,7 +63,7 @@ Before continuing, I recommend you are familiar with the following; - [Test Centre Home](Test-Centre-Home) - [TestCentre Breakdown](TestCentre-Breakdown) - [Property and Unit Tests Overview](Property-and-Unit-Tests-Overview) -- [Console and Library Tests Overview](Console-and-Library-Test-Overview) +- [Console and Library Tests Overview](Console-and-Library-Tests-Overview) ### As a Command-Line Interface (C.L.I.) diff --git a/_sidebar.md b/_sidebar.md index 034e7ea..b8d6b6f 100644 --- a/_sidebar.md +++ b/_sidebar.md @@ -20,7 +20,7 @@ - [Test Centre Home](Test-Centre-Home) - [TestCentre Breakdown](TestCentre-Breakdown) - [Property and Unit Tests Overview](Property-and-Unit-Tests-Overview) -- [Console and Library Tests Overview](Console-and-Library-Test-Overview) +- [Console and Library Tests Overview](Console-and-Library-Tests-Overview) ### As a Command-Line Interface (C.L.I.)