master
Craig Oates 4 years ago
parent
commit
c642772583
  1. 143
      Console-and-Library-Tests-Overview.md

143
Console-and-Library-Tests-Overview.md

@ -1,72 +1,71 @@
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://git.abbether.net/craig.oates/Death-Socket/blob/master/TestCentre/ConsoleTests.fs)
- [LibraryTests.fs](https://git.abbether.net/craig.oates/Death-Socket/blob/master/TestCentre/LibraryTests.fs)
The general structure for these files are the same. Each one has three
modules called `TestingHelpers`, `PropertyTests` and `UnitTests`. It
is worth pointing out every one of these modules live in
name-spaces. This is what allows both "testing" files to use the same
module names. 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).
![test explorere screenshot
simple](test-explorer-screenshot-simple.png)
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 files basic
structure](test-files-basic-structure.png).
One way to denote a property test from a unit test is by looking at
their attributes. If a test has `[<Property>]` next to it, it is a
property test. If a test has `[<Fact>]` next to it, it is a unit
test. For example,
```f#
// This is a unit test -- uses xUnit.
[<Fact>]
let ``Colour map is not empty`` () =
Assert.NotEmpty colourList
// This is a property test -- uses FsCheck.
[<Property>]
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:
![testcenre file structure](testcentre-file-structure.png)
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.
![add new folder
screenshot](add-new-folder-screenshot.png)
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://git.abbether.net/craig.oates/Death-Socket/src/branch/master/TestCentre/ConsoleTests.fs)
- [LibraryTests.fs](https://git.abbether.net/craig.oates/Death-Socket/src/branch/master/TestCentre/LibraryTests.fs)
The general structure for these files are the same. Each one has three
modules called `TestingHelpers`, `PropertyTests` and `UnitTests`. It
is worth pointing out every one of these modules live in
name-spaces. This is what allows both "testing" files to use the same
module names. 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).
![test explorere screenshot
simple](test-explorer-screenshot-simple.png)
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 files basic
structure](test-files-basic-structure.png).
One way to denote a property test from a unit test is by looking at
their attributes. If a test has `[<Property>]` next to it, it is a
property test. If a test has `[<Fact>]` next to it, it is a unit
test. For example,
```f#
// This is a unit test -- uses xUnit.
[<Fact>]
let ``Colour map is not empty`` () =
Assert.NotEmpty colourList
// This is a property test -- uses FsCheck.
[<Property>]
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:
![testcenre file structure](testcentre-file-structure.png)
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.
![add new folder screenshot](add-new-folder-screenshot.png)

Loading…
Cancel
Save