<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Mutation Testing on Stuart Forrest</title><link>https://www.uglydirtylittlestrawberry.co.uk/categories/mutation-testing/</link><description>Recent content in Mutation Testing on Stuart Forrest</description><generator>Hugo -- gohugo.io</generator><language>en-uk</language><lastBuildDate>Fri, 08 Nov 2024 22:23:21 +0000</lastBuildDate><atom:link href="https://www.uglydirtylittlestrawberry.co.uk/categories/mutation-testing/" rel="self" type="application/rss+xml"/><item><title>Using Stryker Runner VS Code Extension in monorepos</title><link>https://www.uglydirtylittlestrawberry.co.uk/posts/stryker-runner-vscode-extension-in-monorepos/</link><pubDate>Fri, 08 Nov 2024 22:23:21 +0000</pubDate><guid>https://www.uglydirtylittlestrawberry.co.uk/posts/stryker-runner-vscode-extension-in-monorepos/</guid><description>&lt;p>This post is about an update that I&amp;rsquo;ve made to the Stryker Runner Visual Studio Code extension I built enabling it to work much better with monorepos. For more information about the extension please see &lt;a href="https://www.uglydirtylittlestrawberry.co.uk/posts/stryker-runner-vscode-extension/">this post&lt;/a>.&lt;/p>
&lt;ul>
&lt;li>&lt;a href="#what-is-stryker">What is Stryker?&lt;/a>&lt;/li>
&lt;li>&lt;a href="#what-is-mutation-testing">What is mutation testing?&lt;/a>&lt;/li>
&lt;li>&lt;a href="#what-is-vs-code">What is VS Code?&lt;/a>&lt;/li>
&lt;li>&lt;a href="#stryker-runner-whats-changed">Stryker Runner: what&amp;rsquo;s changed?&lt;/a>&lt;/li>
&lt;/ul>
&lt;h2 id="what-is-stryker">What is Stryker?&lt;/h2>
&lt;p>The &lt;a href="https://stryker-mutator.io">Stryker&lt;/a> project is a collection of libraries for languages including C# , Scala and Javascript that are used to run mutation tests against your codebase.&lt;/p>
&lt;h2 id="what-is-mutation-testing">What is mutation testing?&lt;/h2>
&lt;p>&lt;a href="https://en.wikipedia.org/wiki/Mutation_testing">Mutation testing&lt;/a> is the programmatic changing or rewriting of parts of your code (a mutant) and validating whether the existing unit tests fail. The idea is that they do fail (killing the mutant), that is the theory anyway if you want to kill 100% of mutants.&lt;/p>
&lt;p>Unit testing frameworks (like Jest for Javascript) can tell you how much of your code is covered by unit tests but this really just means which code gets executed under the tests. Unit testing frameworks cannot tell you how much of the desired behaviour is adequately tested and this information is a part of what mutation testing attempts to solve. The Stryker &lt;a href="https://stryker-mutator.io/docs">docs&lt;/a> have a brief intro on this as well.&lt;/p>
&lt;h2 id="what-is-vs-code">What is VS Code?&lt;/h2>
&lt;p>&lt;a href="https://code.visualstudio.com">Visual Studio Code&lt;/a> (VS Code) is free and widely used IDE developed by Microsoft. VS Code has access to an &lt;a href="https://marketplace.visualstudio.com">official marketplace&lt;/a> of extensions that are used to add additional functionality, integrate libraries like Stryker and even add additional language support. There are also unofficial marketplaces that can be used instead of, or as well as, the official one, e.g. the open source marketplace &lt;a href="https://open-vsx.org">Open VSX&lt;/a>.&lt;/p>
&lt;h2 id="stryker-runner-whats-changed">Stryker Runner: what&amp;rsquo;s changed?&lt;/h2>
&lt;p>The Stryker Runner extension has been useful for engineers that I have introduced it to and for those who have discovered it through other channels. Recently though we have started working with monorepos and have found that the experience using the extension was not quite as good as when working on single project repositories.&lt;/p>
&lt;h3 id="what-was-the-problem">What was the problem?&lt;/h3>
&lt;p>When attempting to run Stryker against a file or code selection in a monorepo Stryker was more often than not unable to locate a relevant &lt;code>node_modules&lt;/code> folder that it could symlink into the Stryker sandbox. This was not an issue if you choose to mutate &lt;a href="https://stryker-mutator.io/docs/stryker-js/configuration/#inplace-boolean">in place&lt;/a>.&lt;/p>
&lt;p>When preparing a sandbox Stryker works its way up the file tree from the current working directory from where the &lt;code>stryker&lt;/code> command was run looking for &lt;code>node_modules&lt;/code> folder. Unfortunately, the extension had been built to execute commands from the root of VSCode Workspace that the target file belonged to. In a monorepo there may or may not be a relevant &lt;code>node_modules&lt;/code> folder in the root of the Workspace depending on how the dependencies are being manged.&lt;/p>
&lt;h3 id="how-did-we-solve-it">How did we solve it?&lt;/h3>
&lt;p>I&amp;rsquo;ve recently released an &lt;code>0.0.47&lt;/code> release of Stryker Runner that changes its behaviour so that it no longer uses the root of the VSCode Workspace as the working directory from which to run the &lt;code>stryker&lt;/code> command. Instead it locates the nearest ancestor &lt;code>package.json&lt;/code> file to the target on which Stryker is going to be run and uses that as the current working directory.&lt;/p>
&lt;p>This change is intended to ensure that when the Stryker Runner extension is used and Stryker works its way up the file tree from the current working directory looking for a &lt;code>node_modules&lt;/code> folder it should always find the appropriate set of dependencies for the target.&lt;/p>
&lt;p>The source for the Stryker Runner extension is available on &lt;a href="https://github.com/slcp/stryker-runner">Github&lt;/a>.&lt;/p>
&lt;p>The Stryker Runner extension can be downloaded from:&lt;/p>
&lt;ul>
&lt;li>As &lt;code>.vsix&lt;/code> package &lt;a href="https://github.com/slcp/stryker-runner/releases">directly from Github&lt;/a>&lt;/li>
&lt;li>The &lt;a href="https://marketplace.visualstudio.com/items?itemName=pixabelle.stryker-runner">VS Code marketplace&lt;/a>.&lt;/li>
&lt;li>The &lt;a href="https://open-vsx.org/extension/pixabelle/stryker-runner">Open VSX Registry&lt;/a>&lt;/li>
&lt;/ul>
&lt;h3 id="get-in-contact">Get in contact&lt;/h3>
&lt;p>If you have comments, questions or better ways to do anything that I have discussed in this post then please get in contact via &lt;a href="https://linkedin.com/in/stuart-f-41a43b180">LinkedIn&lt;/a> or &lt;a href="mailto:stuart@uglydirtylittlestrawberry.co.uk">email&lt;/a>.&lt;/p></description></item><item><title>Stryker Runner VS Code Extension</title><link>https://www.uglydirtylittlestrawberry.co.uk/posts/stryker-runner-vscode-extension/</link><pubDate>Sat, 10 Sep 2022 18:12:21 +0000</pubDate><guid>https://www.uglydirtylittlestrawberry.co.uk/posts/stryker-runner-vscode-extension/</guid><description>&lt;p>This post is about the Stryker Runner Visual Studio Code extension that is intended to allow users to easily and selectively run the Stryker mutation testing library against Javascript and Typescript projects.&lt;/p>
&lt;ul>
&lt;li>&lt;a href="#what-is-stryker">What is Stryker?&lt;/a>&lt;/li>
&lt;li>&lt;a href="#what-is-mutation-testing">What is mutation testing?&lt;/a>&lt;/li>
&lt;li>&lt;a href="#what-is-vs-code">What is VS Code?&lt;/a>&lt;/li>
&lt;li>&lt;a href="#stryker-runner-the-extension">Stryker Runner: the extension&lt;/a>&lt;/li>
&lt;li>&lt;a href="#summary">Summary&lt;/a>&lt;/li>
&lt;/ul>
&lt;h2 id="what-is-stryker">What is Stryker?&lt;/h2>
&lt;p>The &lt;a href="https://stryker-mutator.io">Stryker&lt;/a> project is a collection of libraries for languages including C# , Scala and Javascript that are used to run mutation tests against your codebase. In the context of this post Stryker will always be referring to the Javascript/Typescript library, the extension does not currently support any other languages.&lt;/p>
&lt;h2 id="what-is-mutation-testing">What is mutation testing?&lt;/h2>
&lt;p>&lt;a href="https://en.wikipedia.org/wiki/Mutation_testing">Mutation testing&lt;/a> is the programmatic changing or rewriting of parts of your code (a mutant) and validating whether the existing unit tests fail. The idea is that they do fail (killing the mutant), that is the theory anyway if you want to kill 100% of mutants.&lt;/p>
&lt;p>Unit testing frameworks (like Jest for Javascript) can tell you how much of your code is covered by unit tests but this really just means which code gets executed under the tests. Unit testing frameworks cannot tell you how much of the desired behaviour is adequately tested and this information is a part of what mutation testing attempts to solve. The Stryker &lt;a href="https://stryker-mutator.io/docs">docs&lt;/a> have a brief intro on this as well.&lt;/p>
&lt;h2 id="what-is-vs-code">What is VS Code?&lt;/h2>
&lt;p>&lt;a href="https://code.visualstudio.com">Visual Studio Code&lt;/a> (VS Code) is free and widely used IDE developed by Microsoft. VS Code has access to an &lt;a href="https://marketplace.visualstudio.com">official marketplace&lt;/a> of extensions that are used to add additional functionality, integrate libraries like Stryker and even add additional language support. There are also unofficial marketplaces that can be used instead of, or as well as, the official one, e.g. the open source marketplace &lt;a href="https://open-vsx.org">Open VSX&lt;/a>.&lt;/p>
&lt;h2 id="stryker-runner-the-extension">Stryker Runner: the extension&lt;/h2>
&lt;p>Why bother writing an extension for VS Code now when the Stryker library for Javascript project has been around for 5 years at this point? Mostly because of the experience I have been having working with projects that heavily use Stryker mutation testing, I found that the developer experience was a little painful.&lt;/p>
&lt;p>I think there is a lot of value in mutation testing your projects and I think Stryker is a great option. But because of the nature of what mutation testing is, what Stryker is trying to achieve and how it works Stryker can be a little painful to use sometimes. Depending on the size and complexity of the codebase, as well as the computing resources available, Stryker tests can be incredibly time consuming to run and lengthen the development feedback loop.&lt;/p>
&lt;p>With Stryker you can run mutation testing against single files as well as against specific line ranges in files using the CLI. These approaches can really shorten that potential feedback loop during local development. The original idea of this extension was to surface this functionality into VS Code for developers.&lt;/p>
&lt;h3 id="how-do-i-use-it">How do I use it?&lt;/h3>
&lt;ul>
&lt;li>Against single files:
&lt;ol>
&lt;li>Right click on a file in the file tree in VS Code&lt;/li>
&lt;li>This will present the context menu, the extension adds an item to the menu: &lt;code>Run Strkyer on file&lt;/code>&lt;/li>
&lt;li>Choosing this option will run Stryker against just that file in a new terminal&lt;/li>
&lt;/ol>
&lt;/li>
&lt;li>Against a line range in a file:
&lt;ol>
&lt;li>Select some code in a file in VS Code&lt;/li>
&lt;li>Right click within the file&lt;/li>
&lt;li>This will present the context menu, the extension adds an item to the menu: &lt;code>Run Strkyer&lt;/code>&lt;/li>
&lt;li>Choosing this option will run Stryker against the selected line range in just that file in a new terminal&lt;/li>
&lt;/ol>
&lt;/li>
&lt;/ul>
&lt;h2 id="summary">Summary&lt;/h2>
&lt;p>A small group of developers have so far found the Stryker Runner extension to be useful, saving a lot of time in resolving the outputs from the mutation tests. If Stryker Runner sounds like something that might be useful in your workflow it would be great if you could give it a try. If there any issues, bugs, feature requests of any other kind of feeback please do get in contact or create an issue in the repo.&lt;/p>
&lt;p>The source for the Stryker Runner extension is available on &lt;a href="https://github.com/slcp/stryker-runner">Github&lt;/a>.&lt;/p>
&lt;p>The Stryker Runner extension can be downloaded from:&lt;/p>
&lt;ul>
&lt;li>As &lt;code>.vsix&lt;/code> package &lt;a href="https://github.com/slcp/stryker-runner/releases">directly from Github&lt;/a>&lt;/li>
&lt;li>The &lt;a href="https://marketplace.visualstudio.com/items?itemName=pixabelle.stryker-runner">VS Code marketplace&lt;/a>.&lt;/li>
&lt;li>The &lt;a href="https://open-vsx.org/extension/pixabelle/stryker-runner">Open VSX Registry&lt;/a>&lt;/li>
&lt;/ul>
&lt;h3 id="get-in-contact">Get in contact&lt;/h3>
&lt;p>If you have comments, questions or better ways to do anything that I have discussed in this post then please get in contact via &lt;a href="https://linkedin.com/in/stuart-f-41a43b180">LinkedIn&lt;/a> or &lt;a href="mailto:stuart@uglydirtylittlestrawberry.co.uk">email&lt;/a>.&lt;/p></description></item></channel></rss>