Test::Nginx

Test::Nginx is a test framework that drives test cases written for any code running atop NGINX, and also, naturally, the NGINX core itself. It is written in Perl because of the rich testing facilities and toolchain already accumulated in the Perl world for years. Fortunately, the user does not really need to know Perl for writing test cases atop this scaffold since Test::Nginx provides a very simple notation to present the test cases in a specification-like format.

The simple test specification format, or language, used in Test::Nginx is just a dialect of the more general testing language provided by the Test::Base testing module in the Perl world. In fact, Test::Nginx is just a subclass of Test::Base in the sense of object-oriented programming. This means that all the features offered by Test::Base is available in Test::Nginx and Test::Nginx just provides handy primitives and notations that simplify testing in the NGINX and OpenResty context. The core idea of Test::Base is so useful that we have been using testing scaffolds based on Test::Base in many different projects even including Haskell programs and Linux kernel modules. Test::Nginx is such an example we created for the NGINX and OpenResty world. Detailed discussion of the Test::Base framework itself is beyond the scope of this book, but we will introduce the important features of Test::Base that are inherited by Test::Nginx in the later sections.

Test::Nginx is distributed via CPAN, the Comprehensive Perl Archive Network, just like most of the other Perl libraries. If you already have perl installed in your system (many Linux distributions ship with perl by default), then you can install Test::Nginx with the following simple command:

cpan Test::Nginx

For the first time that the cpan utility is run, you may be prompted to configure the cpan utility to fit your requirements. If you are unsure about those options, just choose the automatic configuration option (if available) or just accept all the default settings.

Test::Nginx provides several different testing classes for different user requirements. The most frequently used one is Test::Nginx::Socket. The rest of this chapter will focus on this testing class and its subclasses. We will use the names Test::Nginx and Test::Nginx::Socket interchangeably from now on to mean the Test::Nginx::Socket test module and its subclasses, unless otherwise specified.

Note
There is actually another different testing scaffold called Test::Nginx, created by Maxim Dounin and maintained by the official NGINX team. That testing module is shipped with the official NGINX test suite and has no relationship with our Test::Nginx except that both of these are meant to test NGINX related code. The NGINX team’s Test::Nginx requires the user to directly code in Perl to convey all the test cases, which means that tests written for their Test::Nginx are not data driven and requires decent knowledge about Perl programming.

results matching ""

    No results matching ""