Writing tests for CLI tool

This page summarizes the projects mentioned and recommended in the original post on dev.to

InfluxDB - Power Real-Time Data Analytics at Scale
Get real-time insights from all types of time series data with InfluxDB. Ingest, query, and analyze billions of data points in real-time with unbounded cardinality.
www.influxdata.com
featured
SaaSHub - Software Alternatives and Reviews
SaaSHub helps you find the best software and product alternatives
www.saashub.com
featured
  • CommandLineUtils

    Command line parsing and utilities for .NET

  • I want to test how my tools generated files and folders in the destination with different arguments passed to the program. However, in my old code, I put all the logic of working with arguments in the static int main( string[] args) function. I could not use Interface and Dependency injection to mock the CLI tools because CommandLineUtils does not have an interface library. Luckily, I found this guidance from the owner of CommandLineUtils, and he advised that "Split the command-line argument parser and application execution into separate class structures" to test various options programmatically. It is a great suggestion, and I rewrote my program by adding class CommandLineOptions and adding logic to class Generator to make it works with CommandLineOptions. I can kill two birds with one stone by this change: code refactoring and writing better tests. Another problem I had was my folder structure. Before, I put the project's sln file, .git file , and src files in the root of the folder. However, when I added a new test project for Shinny-SSG, I had it outside my git folder, and it would be impossible to commit the change and put it in my remote repository. To resolve this, I had to change my folder structure to this:

  • xUnit

    xUnit.net is a free, open source, community-focused unit testing tool for .NET.

  • The testing framework that I chose is XUnit. The first reason is that it is trendy compared to another test framework such as NUnits. I created test methods stub from the existing code by Create Unit Tests command. To use it with Xunit, I have to implement the XUnit.net.TestGenerator extension to my project.

  • InfluxDB

    Power Real-Time Data Analytics at Scale. Get real-time insights from all types of time series data with InfluxDB. Ingest, query, and analyze billions of data points in real-time with unbounded cardinality.

    InfluxDB logo
  • shinny-ssg

  • I want to test how my tools generated files and folders in the destination with different arguments passed to the program. However, in my old code, I put all the logic of working with arguments in the static int main( string[] args) function. I could not use Interface and Dependency injection to mock the CLI tools because CommandLineUtils does not have an interface library. Luckily, I found this guidance from the owner of CommandLineUtils, and he advised that "Split the command-line argument parser and application execution into separate class structures" to test various options programmatically. It is a great suggestion, and I rewrote my program by adding class CommandLineOptions and adding logic to class Generator to make it works with CommandLineOptions. I can kill two birds with one stone by this change: code refactoring and writing better tests. Another problem I had was my folder structure. Before, I put the project's sln file, .git file , and src files in the root of the folder. However, when I added a new test project for Shinny-SSG, I had it outside my git folder, and it would be impossible to commit the change and put it in my remote repository. To resolve this, I had to change my folder structure to this:

NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a more popular project.

Suggest a related project

Related posts

  • Optimizing C# code analysis for quicker .NET compilation

    4 projects | dev.to | 14 Nov 2023
  • Integration testing in Umbraco 10+: Validating document types

    1 project | dev.to | 3 Oct 2023
  • Comprehensive Unit Testing: A Line-by-Line Approach

    2 projects | dev.to | 12 Sep 2023
  • FluentValidation in .NET

    1 project | dev.to | 30 Jun 2023
  • NUnit vs XUnit for .net6+ microservices

    7 projects | /r/dotnet | 1 Mar 2023