Products

Solutions

Resources

Partners

Community

About

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

The Community Blog is a personal opinion of community members and by no means the official standpoint of DNN Corp or DNN Platform. This is a place to express personal thoughts about DNNPlatform, the community and its ecosystem. Do you have useful information that you would like to share with the DNN Community in a featured article or blog? If so, please contact .

The use of the Community Blog is covered by our Community Blog Guidelines - please read before commenting or posting.


DNN Unit/Integration Testing - Part 1

Introduction

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.

Prerequisites

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.

Getting Stared

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.


App.Config Changes

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.

<connectionStrings>

  <add name="SiteSqlServer" providerName="System.Data.SqlClient"

       connectionString="Server=(local);Database=dnnce;Integrated Security=True" />

</connectionStrings>

<appSettings>

  <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" />

</appSettings>

<data defaultProvider="SqlDataProvider">

  <providers>

    <clear />

    <add name="SqlDataProvider" type="DotNetNuke.Data.SqlDataProvider, DotNetNuke" connectionStringName="SiteSqlServer" upgradeConnectionString="" providerPath="~\Providers\DataProviders\SqlDataProvider\" objectQualifier="dnn_" databaseOwner="dbo" />

  </providers>

</data>


Test Results

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.


JWT Tests

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 extension is installed and configured in the targeted test site. Here is a sample test run for the “DotNetNuke.Tests.Urls” integration tests.


Summary:

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.

Comments

There are currently no comments, be the first to post one.

Comment Form

Only registered users may post comments.

NewsArchives


Aderson Oliveira (22)
Alec Whittington (11)
Alessandra Daniels (3)
Alex Shirley (10)
Andrew Hoefling (3)
Andrew Nurse (30)
Andy Tryba (1)
Anthony Glenwright (5)
Antonio Chagoury (28)
Ash Prasad (37)
Ben Schmidt (1)
Benjamin Hermann (25)
Benoit Sarton (9)
Beth Firebaugh (12)
Bill Walker (36)
Bob Kruger (5)
Bogdan Litescu (1)
Brian Dukes (2)
Brice Snow (1)
Bruce Chapman (20)
Bryan Andrews (1)
cathal connolly (55)
Charles Nurse (163)
Chris Hammond (213)
Chris Paterra (55)
Clint Patterson (108)
Cuong Dang (21)
Daniel Bartholomew (2)
Daniel Mettler (181)
Daniel Valadas (48)
Dave Buckner (2)
David Poindexter (12)
David Rodriguez (3)
Dennis Shiao (1)
Doug Howell (11)
Erik van Ballegoij (30)
Ernst Peter Tamminga (80)
Francisco Perez Andres (17)
Geoff Barlow (12)
George Alatrash (12)
Gifford Watkins (3)
Gilles Le Pigocher (3)
Ian Robinson (7)
Israel Martinez (17)
Jan Blomquist (2)
Jan Jonas (3)
Jaspreet Bhatia (1)
Jenni Merrifield (6)
Joe Brinkman (274)
John Mitchell (1)
Jon Henning (14)
Jonathan Sheely (4)
Jordan Coopersmith (1)
Joseph Craig (2)
Kan Ma (1)
Keivan Beigi (3)
Kelly Ford (4)
Ken Grierson (10)
Kevin Schreiner (6)
Leigh Pointer (31)
Lorraine Young (60)
Malik Khan (1)
Matt Rutledge (2)
Matthias Schlomann (16)
Mauricio Márquez (5)
Michael Doxsey (7)
Michael Tobisch (3)
Michael Washington (202)
Miguel Gatmaytan (3)
Mike Horton (19)
Mitchel Sellers (40)
Nathan Rover (3)
Navin V Nagiah (14)
Néstor Sánchez (31)
Nik Kalyani (14)
Oliver Hine (1)
Patricio F. Salinas (1)
Patrick Ryan (1)
Peter Donker (54)
Philip Beadle (135)
Philipp Becker (4)
Richard Dumas (22)
Robert J Collins (5)
Roger Selwyn (8)
Ruben Lopez (1)
Ryan Martinez (1)
Sacha Trauwaen (1)
Salar Golestanian (4)
Sanjay Mehrotra (9)
Scott McCulloch (1)
Scott Schlesier (11)
Scott Wilkinson (3)
Scott Willhite (97)
Sebastian Leupold (80)
Shaun Walker (237)
Shawn Mehaffie (17)
Stefan Cullmann (12)
Stefan Kamphuis (12)
Steve Fabian (31)
Steven Fisher (1)
Tony Henrich (3)
Torsten Weggen (3)
Tycho de Waard (4)
Vicenç Masanas (27)
Vincent Nguyen (3)
Vitaly Kozadayev (6)
Will Morgenweck (40)
Will Strohl (180)
William Severance (5)
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out