DSP2017, DSP2017 Project

Adding xUnit to my .Net Core app – programming at night sucks!

The last two evenings I reserved for coding. The plan was like this – download all the Polish companies, save them in database and make some functionality in ‘admin area’. But of course first things first – unit tests!

I have to admit, most of the code I write doesn’t have tests. It’s not something I’m proud of but life is life, deadline is deadline – but once again – it’s something that really (really – really!) makes me feel ashamed. So, this time I want to make my pet project properly and write as much unit tests as it’s possible. And I’m really curious if I will stick to this idea till the end of ReMaster. Anyway, forgive me if my tests will be bizarre ;).

Stairway to…

I installed xUnit packages. I wrote a test just for the purpose of checking if everything is fine aaaand… The test didn’t appear in the Test Explorer. After an hour or so I decided that it’s quite late hours for solving such trivial and stupid problems. Let’s use console and start doing something bigger, finally!

So I typed

And received the following:

So I added

to project.json of my test’s project so it’s content looks like this:

This time I received even ‘better’ error message:

Oook, that’s strange…

Because it was long after midnight a great idea came to my mind: “Why the hell I chose xUnit, when I can use NUnit and finally do some meaningful code?!” Yes, I did it – I removed all the xUnit references and added NUnit packages. But hey! Don’t judge me, it was 3:30 AM! Who is responsible at this hour? 😉

In fact I don’t even remember what I was doing in my project with NUnit but you may be ‘surprised’ – in the result, it didn’t show anything in Test Explorer.

This way, I started feeling something close to hate to my pet project so I was able to come back to the topic… two days later ;).

I started back with xUnit. And in some magical way I found that I need dotnet-test-xunit package. And that my project.json lacks

section! Whoah! So I make some changes to the file and it looks like this now:

And you now what? My test appeared in the Test Explorer! Of course I can also run it from the console. Wow! I can finally type some code! That’s incredible! Night coding without possibility of drinking coffee (yes! It’s my poor fate – living without caffeine for more than a year now!) really sucks!

And what are yours night adventures with coding?

Featured image by Robert Bock

Share this: