3

Without an IDE integration, running F# unit tests is pretty cumbersome.

One needs to compile them and then pass the resulting dll to a test runner.

I want to find an easier way to run the kind of tests you find for problems on http://exercism.io/

Any ideas?

Guy Coder
  • 24,501
  • 8
  • 71
  • 136
Adrian
  • 1,006
  • 2
  • 9
  • 20
  • 1
    Also what OS are you on? If you are on Windows then [Visual Studio Community](https://www.visualstudio.com/en-us/products/visual-studio-community-vs.aspx) is a free download and install, and [NUnit](https://www.nuget.org/packages/NUnit/) with the [Adapter](https://www.nuget.org/packages/NUnit3TestAdapter/) is also free which will allow you to write and run the test all within Visual Studio. I don't know it this will work with F# Interactive within Visual Studio. – Guy Coder Jul 05 '16 at 17:59
  • At [exercism.io](http://exercism.io/languages/fsharp) for F# in the left side I see: [Installing F#](http://exercism.io/languages/fsharp) and [Running the Tests](http://exercism.io/languages/fsharp) Did you read these? – Guy Coder Jul 05 '16 at 18:10
  • Of course I read them. I'm on Mac OS X. For all OSs the "solution" is to use some IDE. VS or Xamarin. Still, it would be nice to be able to just send the tests to interactive console and have them executed. – Adrian Jul 05 '16 at 19:01
  • I don't even know if it is possible to get F# Interactive to recognize attributes? e.g. [] or [] – Guy Coder Jul 05 '16 at 19:10
  • This discussion gave the idea to investigate module level reflection. Do you think it's possible? – Adrian Jul 05 '16 at 20:30
  • Something close to http://stackoverflow.com/questions/2297236/how-to-get-type-of-the-module-in-f – Adrian Jul 05 '16 at 20:34
  • I am a bit confused by the last question. To use reflection the code will have to be built, is not that one of the steps you are trying to avoid? Do you mean static analysis? If the code is built, then I don't see anything stopping you from using reflection but if I understand how you want to use, then it would be like going over the mountain instead of around the mountain. – Guy Coder Jul 05 '16 at 20:35
  • 1
    Based on the goal you started with, the best way I see to do it is to just load the IDE and use it. I don't use Xamarin Studio but with Visual Studio, once it is up and running with NUnit and the adapter I just modify the code, then in [Test Explorer](https://msdn.microsoft.com/en-us/library/hh270865.aspx) click run and [view the results](https://msdn.microsoft.com/en-us/library/hh270865.aspx#BKMK_View_test_results), then modify code and run again, and again ... . I don't see how it could be much simpler. – Guy Coder Jul 05 '16 at 20:42
  • 1
    Can't you just use the various console runners - for example nunit here http://www.nunit.org/index.php?p=nunit-console&r=2.2.10 – John Palmer Jul 05 '16 at 23:32
  • FSI is compiling the code anyway based on the script at hand. Since it is building in order tobrun it, why not test it? @johnpalmer. As stated in the question, I want to avoid this explicit build step which is complex without an IDE. I know there are command line alternatives but they still require a project being set-up. Which is a bit overkill for simple cases like exercism. – Adrian Jul 06 '16 at 04:54
  • I think that you are over complicating the difficulty of compliling - a makefile based approach is pretty simple for small projects and will typically require about 2 lines of make. Otherwise, I think a runner that worked in F# would be possible in theory but probably difficult. – John Palmer Jul 06 '16 at 04:57
  • If you massage the test code to avoid the attributes then you should be able to do it. See: [Use F# to run unit tests programmatically](https://fsharpforfunandprofit.com/posts/low-risk-ways-to-use-fsharp-at-work-3/#test-runner) I have not used this so take it with a grain of salt. If this helps you to solve your problem you should post what you get working as an answer and get yourself some easy points. – Guy Coder Jul 06 '16 at 11:14
  • How are you doing? Did you get unit test to run from F# interactive working yet? If not let me know and I will give it a run through and it if works post an answer. I prefer to let others answer there own question if there are enough hints and it is simple enough; it helps them learn more than seeing the answer. – Guy Coder Jul 07 '16 at 13:17
  • I'll give it a go tomorrow. If I have time. :) – Adrian Jul 07 '16 at 17:32
  • Hi @Guy Coder, I didn't manage to compile a decent solution for the question. You are free to answer and thanks for giving me the opportunity but I didn't manage to rise to the expectations. :) – Adrian Jul 08 '16 at 08:15
  • I have something working but I am holding off on putting it here because at this point it is just nuts and bolts; many batch and fsi files that build an environment to load the needed libraries, e.g. paket, NUnit, Fake, FuChu etc. Many of the examples I pointed out are dated and the FuChu code expects members where the exercism test are not members so need to do more work. It is a good problem for a coding dojo because it makes you have to dig into the tools mentioned. Anyway wanted to let you know I have not forgot about this, but I did lower it's priority. – Guy Coder Jul 11 '16 at 12:51
  • FYI: If you massage the test then doing this for exercism.io this is easy, but I want to see if I can get it to work with the NUnit test without modification because many projects have them built into them that way and if one has to massage the test code then it is not worth the trouble. So spending time with reflection. – Guy Coder Jul 11 '16 at 12:58
  • Just found this, looks like it might be of help: [Forge](https://github.com/fsprojects/forge). Never used it. Adding reference for when I come back to this problem. – Guy Coder Aug 06 '16 at 17:14

0 Answers0