Next.JS - testing async React components

I had the great joy of teaching a course on Next JS 13 this last week. Next has for a long time been a favorite of mine and with version 13 they have really stepped it up a notch. Or three. But what they still are lacking, and for the life of me I cannot understand why, is a good out-of-the-box testing story. This caused me and the group I was teaching considerable head-ache - especially when we tried to test the server-side async components that Next.JS is plugging hard. Therefor I have two goals with this post: Help me (and you?) to easily get started with testing Show a way to test async server components Let’s do this.
Read More

Deploying. NET 6 WebAPI using ARM Template

I’m putting together a course where I want students to easily deploy their code. Since the course is on .NET 6 WebAPIs (and Entity Framework (core)) I thought that Azure would make a great choice to deploy to. And nowadays ARM templates seems to be the way to go (maybe BICEPs but I’m doing ARM for now). But I ran into problems, and I wanted to share with you those problems and how I overcame it. Just your normal post on this blog in other words. Creating the API The course is pretty fast moving and I needed them to be up and running fast, so my idea is to create a very simple, walking skeleton, version of the application; by adding value in a simple Developers table. Turns out that is quite a lot of steps involved, that I don’t want to take time from the course to do....
Read More

Plans are theoretical

I just had an aha-experience that shook me; first I found it interesting, and then I was ashamed that I haven’t realized this before. Here it is: Plans are theoretical Let me tell you how I realized this and how I think it is important. At </salt> we’re planning to run yet another Graduation Day, after 35 new developers has been created. That is amazing in itself to be part of, but not the topic of this post. Someone (Sara - excellent co-worker), called me and asked me the following: Do we have an agenda for the day? We sure did, but she was asking me a follow-up question: Will the after-graduation mingle start at 17? Now, that is a good question but also where theory meets reality. Not Sara’s fault I want to stress but when I realized it. Because we had written out timings that said that the...
Read More

Testing WebAPI with AspNetCore.Mvc.Testing and xUnit Collections

I’m writing a boot camp for .NET core and have started to learn a lot of things that have changed since I last coded C#. One of them was shown to me by my good friend John Magnusson. (I’m downplaying his knowledge and skills a lot here since I was close to tears and he sent me a link that saved by bacon, but hey - I’m telling the story :)) Anyhow - John showed me Microsoft.AspNetCore.Mvc.Testing that really tells a nice story when it comes to testing an API. In this post I wanted to show you how I used it. Also - I ran into problems, since I had a database seeding that didn’t work when I used the suggested solution. I will show you how I solved that too, and in the process, tell you a little thing I picked up about xUnit. And a bit about...
Read More

xUnit - closing Selenium driver after ALL test in suite

I’m enjoying myself at work right now, writing a course in C# and for the .NET core platform. Man - this was some time ago. Naturally I learn a lot. That’s why I became a teacher. I wanted to share a little nugget (NuGet?) of gold that I found. In one of the early labs in the course I used Selenium to write some end-to-end tests. And in doing so I need to create Driver object, that is both pretty heavy to start and, if left after the test run, quickly will eat your memory. Now, I was using xUnit as my testing framework and xUnit doesn’t have a notion of test suites. This was bad since I wanted to create the Driver object on the first e2e test and not tear it down until the last. My intial attempt looked like this: using System; using Xunit; using OpenQA.Selenium; using...
Read More

A data-driven prognosis report

I have a big project ahead here at Salt - I’m going to write an entire boot camp from scratch. This is done as a single-person project and all my other colleagues are working on as normal around me. I wanted to report my progress to them so that they know what’s happening and also that I can get some leeway of keeping my focus. In this post, I wanted to share a very simple prognosis tool that I created based on the data that my work create. As always, it’s not perfect but it will give an accurate enough feel for where I am and when it will be done A few words about the project Unlike most software development projects I’ve been in the scope of this project is very clear; I’m going to write slides, labs, and instructions for 13 weeks, 5 days a week The topic...
Read More

Writing a Selenium test using .NET core and Visual Studio Code

I’m rediscovering my first programming love; .NET. I’m having a blast and .NET core keeps giving. This post is one of those - I can’t believe that I couldn’t find this post on the net somewhere. Or I didn’t look hard enough. But I wanted to setup Selnium testing, but only use .NET Core and Visual Studio Code on my Mac. Every example I saw was using older versions of .NET core (I’m writing this on .NET core 5) and/or Visual Studio, which I don’t have. Installations First, to make .NET and C# developement pretty good in a code editor, we need a few addons to Visual Studio: C# extension I also installed Prettier and added support for C# code formatting using the following snippet in my setttings.json-file "[csharp]": { "editor.defaultFormatter": "ms-dotnettools.csharp" } Ok - then of course you need to have .NET core installed on you computer. With that...
Read More

Making boring fun - bash and Node to the rescue

I rarely get paid to write code these days… or that is people rarely ask me to write code. But since I’m a programmer at heart it is one of the tools in my toolbelt, regardless of what kind of tasks I’m given. Today I got asked: Could you please list all Open Source Licenses we are using, and all the dependencies all our code is using. Considering we have 130+ repositories I was what the scientist refer to as a boring task. Let’s make it more fun with code. I’m gonna wield my bash- and Node-swords to solve this sucker. And I was looking to do some functional programming exercises too - let’s see if we can squeeze all of that in there. Getting the licenses out of the repos Each repository has a package.json file that contains a license field. After npm install we will get a lot...
Read More

When I learned a safety lesson - and did a little bit better

I like to automate repetitive and boring things I do in my daily work. This lead to that me write bash scripts from time to time, but the problem is that I’m a newbie scripter. I’m learning as I go. And the other day I did a cardinal sin in scripting. Not only that - I decided to show the world. Now that is a point to feel ashamed or to learn. I did both. In this post, I will tell you about how I made my curl-script a little better and a lot safer, but using an old way that’s been in curl for ages. The background I was waiting for the summer part of Salt to start and had an hour over. The weather was amazing and I found a nice tree to sit under. Of course, I flipped up the computer and did some scripting. In fact,...
Read More

Introducing ScrAdd - the script adder

I’ve been increasingly annoyed with the fact there’s no easy way to add scripts to a package.json file programmatically. It always messes up my lovely scripts for tutorial setups and other use cases. Very frustrating. Well … until not that is. I give you ScrAdd - the script adder. Let’s say that you are writing a tutorial on how to test next apps. You want the readers just to get to the place where you can start to talk about code. My friend - just scradd in that command and take the rest of the day off! npx create-next-app demo cd demo npx scradd . test "mocha . -R dot -w" npm i -D mocha I don’t expect this tool to be widely used and spread but I was pretty fun to write it - the testing was particularly tricky to get working. Get the code or download the tool...
Read More