/ C#

Travis-CI, C# and ApprovalTests

I've been experimenting with Travis-CI recently to build a personal project written in C#.

Travis-CI uses a Linux based backend, meaning to build C# projects, we have to use some non-Microsoft tools to get things done.

To build the solutions themselves, Travis uses Mono, and MSTest being Windows only means we have to use an alternate test framework. I chose XUnit as I'd heard a bit about it and wanted to learn more.

The Travis docs are pretty good at getting started with builds and configuring XUnit to run, but I ran into a few problems when trying to write some ApprovalTests.

Every time my build and tests ran, my ApprovalTests would fail. First off, I was told via the build log to add a Reporter, with the suggested one being DiffReporter, so I did my duty and annotated my test class with [UseReporter(typeof(DiffReporter))].

Please add UseReporter

Next time the build ran, I was presented with an object reference exception from deep within the bowels of ApprovalTests.

Object Reference

After much searching, I discovered that I didn't really need a reporter on a CI server, so I switched to [UseReporter(typeof(QuietReporter))].

The build ran again, and this time I was told that ApprovalTests couldn't find my approved test file.

Can't find approved test file

But how!? It was checked in and working locally. It seems like Linux / Mono may have some filesystem quirks or differences that mess up ApprovalTests, as it looks for the approved test files in the bin/[Configuration] rather than the project directory.

To solve this was as simple as including the approved files in the test project, and selecting Copy Always in the file properties:
Copy Always

After doing this and pushing my changes, I saw the sweetest sight ever seen:
Build Passing

And my trials and tribulations with Travis-CI, C# and ApprovalTests were over.

Check out my code for this blog post here