Non-ide development

Hi,

I’ve been learning F# for a while and really love it.
Now I’m ready to move past a simple one-thing project, and thought I’d do the “Ray Tracer Challenge” book but I’m getting lost on how to proceed with integrating testing into a project.
My very strong preference is to use vi and command line tools - because that’s how I’ve been developing for 40yrs - but I can’t find much that explains how dotnet/F# projects fit together; every book I’ve looked at assumes you’ll be using and IDE, Visual Studio or similar.

If nothing else, I need to know how to add testing into a console app - that would get me started on the book.

So, can anyone point me to some good resources? Are there any good resources - or do I need to give up and find an IDE to hold my hand?

thanks
Jonathan.

You should definitely be able to make good progress without an IDE. Even when I use an IDE, I still really only use it for stuff like Go To Definition, and autocomplete and type definitions when I hover on stuff. I use the command line dotnet tool for managing projects & solutions, running tests, etc.

Now, the most oft recommended way to add tests is to have a separate project for the tests, which is pretty easy to setup. You can do dotnet new --list -lang f# to see all of the F#-compatible project templates available on your machine. (Personally I would recommend NUnit or XUnit and not MSTest, since MSTest seems to me especially tailored for C#). Once you have multiple projects, you probably want a “solution” to contain them. So I can do

> dotnet new console -lang f# -n ProdProj
> dotnet new nunit -lang f# -n TestProj
> dotnet new sln -n MySolution
> dotnet sln add ProdProj
> dotnet sln add TestProj
> cd TestProj
> dotnet add reference ../ProdProj

(You probably have that first step already done for your console app). Now you can run dotnet build (or dotnet build MySolution.sln) to build both projects, or dotnet test to run all the tests in the test project.

Sometimes I do like to have my tests in the same project, even if that’s not the recommended approach. What I would do in that case is take a look at the .fsproj that gets created when you run dotnet new nunit -lang f#, and figure out what things to port over to your prod project. In this case, I think the important bits are

  <ItemGroup>
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
    <PackageReference Include="NUnit" Version="3.13.2" />
    <PackageReference Include="NUnit3TestAdapter" Version="4.0.0" />
    <PackageReference Include="coverlet.collector" Version="3.1.0" />
  </ItemGroup>

Copy that into your console app, and now you can add tests directly into that project.

As far as resources go, I mostly just use the --help docs with all the dotnet commands, and then just run google searches on any nodes in the fsproj that I don’t know what they do. There might be some nice comprehensive docs on that stuff, but I don’t know them. If you’re searching for fsproj details, you might want to sometimes try searching with “csproj” instead as your search term, since there’s probably 100x more resources for csproj stuff online, and the two have very similar structures.

A good reference for the project file properties and items can be found on the SDK-specific pages here. You can pick from the different main SDK types (Microsoft.NET.Sdk, Microsoft.NET.Sdk.Web, etc) on the left side to get more details.

image

1 Like

Wow … thanks ntwilson for that - brilliant.
I’ve got a project setup and ran a test and everything!

I can dig into F# deeper now.

Thanks

1 Like