This is an introductory article to guide those who would like to contribute to DNN Platform on how to write tests. In this article, I will explain the structure of the tests in the DNN Platform solution and how to run some/all of the existing tests.
To get your system ready for DNN Platform development and testing you need to have a PC with the following software installed:
- Windows 7 or higher
- .NET Framework 4.5 or higher
- Visual Studio 2015 (any edition; Community, Pro, etc.) or higher
- MS SQL Server 2008 R2 or higher
- NUnit GUI Runner 2.6.4 (this is the compatible version with DNN Platform; not higher ones) or * ReSharper or any other test runner capable of running NUnit tests.
- DNN Platform site installed on the same machine.
Here are the steps to start using the test projects:
- Clone the source code repository to your computer from this location https://github.com/dnnsoftware/Dnn.Platform
- Start Visual Studio as an Administrator.
- Browse to the cloned folder and locate the solution file “DNN_Platform.sln” (under main cloned folder) then open it. You should see a screen similar to this.
The Platform has two types of tests: Unit and Integration. You need to expand the nodes as in the following image to see the various test projects. Also, you need to locate the two “App.config” files for modification at a later time (as shown in the image below).
Unit Tests vs. Integration Tests
The main difference between DNN Unit tests and Integration tests is that the former doesn’t require an installed DNN web site while the latter targets DNN site with FQDN URL. The current architecture of these tests doesn’t contain clear distinction about targeted database and both can utilize a database connection as needed. There are some tests which utilize an instance of MS SQL Server Compact.
The tests are grouped logically into projects according to features. These tests evolved over the lifetime of DNN Platform project and they contain various components that might be common to more than one group or duplicated in some of them.
NUnit Test Runner
All tests are written to utilize the NUnit testing library. The referenced NUnit version is 2.6.4. You need to have this specific version installed in your machine to be able to run the various tests. Each test project generates a DLL that contains its own set of tests and can be run separately under the test runner. To run the tests of a DLL, you need to start the NUnit 2.6.4 runner and load the test DLL. If you are using a newer version of NUnit, you might not be able to run the tests due to some changes in the test attributes in these versions. The NUnit runner is a standalone executable and can be downloaded from NUnit’s official site (http://nunit.org
<) and go to download page. There are two runners: a GUI runner and a command line one.
ReSharper Test Runner
Some developers might have extensions installed in their Visual Studio that allows them to run these tests without leaving the IDE. ReSharper (from JetBrains)
is one of these extensions. Therefore, whether you are using the standalone NUnit runner (GUI or CLI) or an extension in Visual Studio, the tests results will be the same. The extension approach is more convenient and makes it easier to locate and modify the tests without leaving the development environment. Therefore, if you are able to utilize an extension, it would be faster and easier to write and run the tests.
Running Tests on DotNetNuke.Tests.Core
To start, let’s assume you have an extension in your Visual Studio that facilitates running unit tests. As shown in the previous image, browse to the tests folders and select the test you want to run. Suppose we would like to run the core test project (DotNetNuke.Tests.Core) test. To do so, we need to load the core’s DLL tests into the test runner we are using. For this article I will be using the ReSharper test runner. When loading the project tests (or the DLL), we will see a window similar to this.
Or like this if you are using NUnit GUI runner.
Before running the tests, we need to make sure that the settings in the application configuration file of the project we are running tests from is updated to reflect the environment these tests are intended to run for. There are few items to look for usually in these configuration (app.config) files. We need to look into the connection string when pointing to a SQL server database and update the settings for our environment. Also, we need to look under <appSettings> for any entry that is specific to our environment. For example, we need to change the URL in such an entry.
<add name="SiteSqlServer" providerName="System.Data.SqlClient"
<add key="objectQualifier" value="dnn_" />
<add key="siteUrl" value="http://dnnce.lvh.me"
<add key="hostUserName" value="host"
<add key="hostPassword" value="dnnhost"
<add key="loginCookie" value=".DOTNETNUKE"
<add name="SqlDataProvider" type="DotNetNuke.Data.SqlDataProvider,
DotNetNuke" connectionStringName="SiteSqlServer" upgradeConnectionString="" providerPath="~\Providers\DataProviders\SqlDataProvider\" objectQualifier="dnn_" databaseOwner="dbo"
If you don’t change these settings, then some of the tests will fail due to site not accessible errors. After changing these properly and running the tests, you should see all tests passed as shown below.
Similarly, we can run integrations tests to test our site. But, you should beware that some of the tests will not run on any site. An example is the JWT tests; which require that the JWT
is installed and configured in the targeted test site. Here is a sample test run for the “DotNetNuke.Tests.Urls” integration tests.
To run the unit and integration tests that come with DNN Platform, you need to make a few changes to the app.config files included in the tests source code by pointing to your test site’s database, url, and the database table prefix (the objectQUalifier) then running these tests using the NUnit GUI runner or any other tools capable of loading and running DLL’s containing NUnit tests.