Welcome to part 2 of the QAToolKit series, where I focus on the QAToolKit Swagger library.
QA Toolkit is a collection of libraries, tools, and scripts for running automated jobs for assuring smooth development, general and QA testing, and running fitness functions for your applications.
Now let’s focus on the Swagger library.
If you are developing HTTP APIs, you are probably using Swagger to document, test, and share those APIs with your consumers or other developers. Those developers can use Swagger files to see what your APIs are doing and what the contracts are. They can also generate a client code in many languages from Swagger files and then consume your services.
Now that we know what Swagger files are, we can check what the QAToolKit Swagger library can do for us. The whole story about QAToolkit revolves around performing fitness functions, high-level testing, or End-2-End testing if you like. And Swagger library is a data source for performing those actions. We can import a Swagger file and generate a list of requests, which we can use to perform service tests, integration tests, load tests, etc.
The swagger library gives you an abstraction and useful functions over the Swagger file. Here is code that captures the essence of the library:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
// create new Swagger URL source SwaggerUrlSource swaggerSource = new SwaggerUrlSource( options => { options.AddRequestFilters(new RequestFilter() { HttpMethodsWhitelist = new List<HttpMethod>() { HttpMethod.Get } }); }); //To run the Swagger parser we need to pass an array of URLs IEnumerable<HttpRequest> requests = await swaggerSource.Load(new Uri[] { new Uri("https://api.demo.com/swagger/v1/swagger.json"), new Uri("https://api2.demo.com/swagger/v1/swagger.json") }); |
If we look at the code above, we first create a SwaggerUrlSource and add a request filter. The filter will collect only GET requests (GET HTTP Method). Then, we load 2 Swagger URL source files and get a list of requests back (only GET methods).
This on its own is not very useful, but by connecting those request results with other QAToolKit libraries or your own code, you can create something useful. You could pipe the results to the QAToolkit Bombardier or HttpTester libraries and perform the meaningful tests.
There is good documentation on Github, which you can check out in the library source repository.
If you like watching educational videos on YouTube, I invite you to go to my channel and check out the Swagger library’s two videos.
I hope you find QAToolKit useful, and let me know if you have any comments and suggestions. Go to a discord channel or Github page to get in touch!
Ta-da
Leave a Reply
You must belogged in to post a comment.