TIL: How to Debug a Test in Golang With Build Tags in Neovim

TIL: How to Debug a Test in Golang With Build Tags in Neovim I was having issues with my debugger today (well technically yesterday because I am publishing this a day later to spread out my blog posts but same difference) and it took me a few hours to realise what was going on. In my case, I was trying to debug a test written in Golang using nvim-dap-go on Neovim. ...

How to Use Neotest Dap With Lazyvim for Golang Development

In this blog post, I will show you how you can easily setup Neotest to make testing easier in neovim and DAP to make debugging your tests is a lot easier. I am using the LazyVim neovim distribution, where these two come as easily installed extra plugins. However, it should be easy enough for you to copy the config over to your neovim lua config. LazyVim even has the config available on its website, you don’t even need to deep dive into the code 😄. ...

How to Get Code Coverage From Playwright Tests in a Sveltekit App

In this post, I will show you how to get code coverage reports from your Playwright tests in your SvelteKit app. So let’s imagine we are starting with the basic SvelteKit template. First, we need to install: npm i -D vite-plugin-istanbul We need the vite plugin to instrument our code using Istanbul. Istanbul is a tool which allows us to instrument our code such that it can determine which lines were covered by our tests. ...

TIL: How to Mock Classes Using Vitest

TIL: How to Mock Classes Using Vitest Recently I have been creating a SvelteKit app, when creating a new SvelteKit app you get a choice of different things you can add. Such as using vitest for unit testing. I needed to spy on/mock a method in a class, to see if it was called when a button was pressed and, it was called with the correct arguments. Let’s say we have a Button component which looks like this: ...

TIL: How to Use Multiple Auth Files in Playwright

TIL: How to Load Authenticate State in Playwright In this post, I will quickly show you how you can reduce boilerplate code to log in to your app in Playwright tests. Log in to our app is a very common action that will likely be required in most of our tests. You can read this documentation here, which will explain how you can set this up. However, what do you do if you want to say test the login flow or the register flow? ...

E2E tests with Gitlab CI services

Background This will be a slightly shorter article. In this article I will show you how I’ve managed to do some end-to-end testing with Gitlab CI services. I’m building a browser-based multiplayer game called Banter Bus. Banter Bus consists of three main components, gui: A SvelteKit based frontend the user will interact with to play the game core-api: A Socketio API written in Python management-api: A simple RESTful API written in Python (FastAPI) Now say I want to write some e2e Cypress tests, that will test all of these components interacting with each other. ...

Testing a socketio Web App written in Python

In this article I will show you how you can test an async Socketio application in Python, where the ASGI server we are running is uvicorn. I will be referring to these tests as integration tests, though depending on who you ask they could be called E2E tests, system tests, slow test etc. What I am referring to is simply testing out the entire “flow” of a socketio event i.e. emitting an event from a client, then receiving it on the web service and for my actual projects interacting with an actual database. ...

Testing a Gatsby application with Cypress on Gitlab CI

In this blog post, we will go over how we can automatically test a Gatsby site end-to-end (e2e), using Cypress on Gitlab CI. Introduction Gatsby Gatsby is a static site generator (SSG) built upon React. It allows us to create “blazing” fast websites. In this example, we will use a simple blog starter template available and add a Cypress test. Cypress Fast, easy and reliable testing for anything that runs in a browser. ...

Testing a Connexion/Flask Application with Pytest

In this article, I will show you how you can test a Python web service that was built using Connexion (a wrapper library around Flask). We will go over how you can mock functions and how you can test your endpoints. There are two related articles I have written in the past listed below. In the first one we go over how to create a web service using Connexions, the same web service we will in this article. ...

Testing a Flask App with pytest-mock and pytest-flask

Pytest is a popular Python library used for testing. It is my preferred testing library because it requires less boilerplate code than the alternatives such as (the builtin) unittest, the built in testing library. In this article, I will show you how you can use pytest-flask and pytest-mock to test your Flask app. These two libraries are plugins for Pytest which build upon some of the features that Pytest provides us. ...

Pytest with Background Thread Fixtures

Recently I had to test some of my Python 🐍 🐍 🐍 code which required an external dependency and communicating by using TCP sockets 🔌 . You can think of this dependency as essentially a database because it stored information. However, when testing my Python code, I couldn’t rely on there always being a TCP server to send messages to. So I ended up creating a simplified mocked version in Python. ...