Introducing the Nitriq Console Application
One of the nice things about Nitriq is that you can easily run all of your queries against your code base as many times as you want. This falls into the same boat as unit testing: tests should be able to be run quickly at any time. If tests could not be run at any time or if they took a long time to run, then they would be ignored. That would defeat the purpose of having tests. Needing to open a separate application to run a body of tests can introduce this hindrance into the development process. Therefore, we here at NimblePros have also released a console runner for Nitriq in addition to the Nitriq GUI. With this cool new application you can run all of your queries for any Nitriq project in a console window. You can then run your queries against your projects in a quick reliable fashion, which means that you will get into the good habit of running them (along with all of your other tests) on a regular basis. With a small bit of effort you can even have the queries run against your latest build via continuous integration. In this post I’ll show you the basics of running this Nitriq console application with the prepackaged queries and a Nitriq project referencing my Project Euler assemblies and executable.
Here is an instance of the Windows command prompt opened to the directory with the console runner. It also contains the queries to run (the *.nq file) and the Nitriq project to analyze (*.nitriqProj):
Running the application only requires three parameters: the Nitriq project file, the queries file, and the directory to save the generated output file. In this example, I’ll be using the following command:
Nitriq.Console.exe euler.nitriqProj myQueries.nq ./
Since I want the output file to be generated in the current directory, I used “./” to do just that. Let’s run the application and see what we get:
It looks like we had some errors in our analysis. In addition to the generation of the output file, NitriqReport.txt, the application also returns a code of 1 to indicate that the analysis reported some errors. This can be utilized in continuous integration builds to indicate success or failure. Let’s take a peek into the generated output file:
The output file tells us precisely which queries failed and for what reason. In this example, several queries threw warnings (i.e. found instances of broken rules) and one query reported an error (an exception was thrown). Now let’s fix these issues and run the application once more:
Now that the errors have been taken care of, we get “Nitriq Analysis Completed” in the command prompt and a successful return code of 0. As you can see, we can easily re-run the Nitriq console application with the same project and queries, encouraging us to run these queries against our code on a regular basis. Integrating this body of tests into the development cycle will allow even more bugs to be squashed and code smells to be extinguished, yielding a cleaner code base and happier clients. If you make this a part of your continuous integration setup, you can even have the build be considered broken until this application returns a successful message.




