Skip to content

Using Test Frameworks

Tom Clarke edited this page Feb 17, 2019 · 10 revisions

HOWTO

  • Create a new module TestStuff (replace Stuff with appropriate name) with tests for any emulator project code, see below for details
  • Create a new dotnet core console project with TestStuff after all the emulator modules in compile order
  • add Expecto, Expecto.FsCheck NuGet packages to your project
  • Make program.fs main function run a top-level runAlltestsInAssembly function and then as usual wait for a console key before terminating.

Details

Current Status

The Visual2 code at the moment has a specific custom test framework that checks instruction functionality is compatible with Visual. This is useful, but not relevant to add-on functionality.

There is currently no integration of test frameworks into the Visual2 code, mainly because this is normally compiled under FABLE and the low friction testing is all under dotnet core which is not compatible with this. This project does not currently have test frameworks and integration testing that correctly runs emulator-level code through a set of easy to write tests. That is a (bad) lack, and therefore tests must be implemented as F# modules importing the emulator code and running it under dotnet core.

Emulator Testing

The Emulator project code will all compile and run under dotnet core and can initially be tested using Expecto / Fscheck which is very convenient.

Canopy is an alternate (and perhaps better) F# test framework, again for code that can be compiled under dotnet core.

Emulator FABLE/Javascript compiler compatibility

In addition to checking that new emulator F# works when compiled to dotnet core, it is helpful to test whether this code will compile when compiled with FABLE. FABLE implements core F# and some but not all of the many .Net libraries and methods available, see the compatibility guide. If you use random .Net functionality you may have no substitute in FABLE and therefore have to rewrite your code. For this check you don't need a test framework: just run your code under the full Visual2 yarn start compile and check there are no compile or bundle errors.

Emulator FABLE / F# incompatibility

FABLE is another compiler for F# and whether your code runs under .Net (normal compiler) or Javascript via FABLE should make no difference to operation. If a pure function passes tests on one platform it will work the same on the other. This is nearly always true, but not quite because of:

  • Small differences in how numbers are handled. See Numbers
  • Other differences (see guide

In practice you can ignore this issue when doing individual coding - it is unlikely to hit you.

Renderer Testing

The Renderer project code must run compiled by FABLE into Javascript since it has Javascript dependencies. It cannot be tested with Expecto and would need to use a Javascript-oriented test framework such as Jest or Mocha. See the FABLE FAQ. Integrating either these tests frameworks with Visual2 has not been attempted. It would be useful, but some work, to do. You should be familiar with Javascript to do so, because these frameworks use Javascript rather than F# techniques and although the translation from F# to Javascript is pretty good there will be some aspects of using them which are unfamiliar.

I don't expect Visual2 add-ons to have renderer-level tests incorporated now - though long-term this is clearly desirable.

Clone this wiki locally