Click here to Skip to main content
15,893,588 members
Articles / Web Development / XHTML

Performance Benchmarks using NUnit Addin

Rate me:
Please Sign up or sign in to vote.
4.97/5 (16 votes)
27 Oct 2012LGPL312 min read 90.7K   733   74  
This tutorials introduces a new NUnit Addin able to record execution time of unit tests and generate XML, CSV, HTML performances reports with charts and history tracking.
using System;
using System.Collections.Generic;
using System.Text;


namespace NinjaCross.Classes.Nunit.TestPerformance
{
    /// <summary>
    /// This attribute must be applied to the NUNIT test methods that needs for performances benchmarking
    /// </summary>
    [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
    public sealed class NJC_TestPerformanceRecorderAttribute : Attribute
    {
        //----------------------------------------------------------------------------
        #region Members
        //----------------------------------------------------------------------------

        /// <summary>
        /// The optional test logic name
        /// </summary>
        private string _testName;
        /// <summary>
        /// The optional test description
        /// </summary>
        private string _testDescription;
        /// <summary>
        /// The target where the output reports must be written to
        /// </summary>
        private string _outputTarget;
        /// <summary>
        /// The write mode of the output reports
        /// </summary>
        private NJC_TestPerformanceTargetWriteMode _outputTargetWriteMode = NJC_TestPerformanceTargetWriteMode.Append;
        /// <summary>
        /// The format of the output reports
        /// </summary>
        private NJC_TestPerformanceTargetFormat _outputTargetFormat = NJC_TestPerformanceTargetFormat.Xml;
        /// <summary>
        /// The format used to generate the identification key of the output reports generated by this attribute
        /// </summary>
        private NJC_TestPerformanceTargetIdentificationFormat _outputTargetIdentificationFormat = NJC_TestPerformanceTargetIdentificationFormat.ClassFullNameAndMethodName;
        /// <summary>
        /// The target type
        /// </summary>
        private NJC_TestPerformanceTargetKind _outputTargetKind = NJC_TestPerformanceTargetKind.FileSystem;

        //----------------------------------------------------------------------------
        #endregion
        //----------------------------------------------------------------------------

        //----------------------------------------------------------------------------
        #region .CTORs
        //----------------------------------------------------------------------------

        //----------------------------------------------------------------------------
        public NJC_TestPerformanceRecorderAttribute()
        {

        }

        //----------------------------------------------------------------------------
        public NJC_TestPerformanceRecorderAttribute(String testName, String description)
            : this()
        {
            _testName = testName;
            _testDescription = description;
        }

        //----------------------------------------------------------------------------
        #endregion
        //----------------------------------------------------------------------------


        //----------------------------------------------------------------------------
        #region Properties
        //----------------------------------------------------------------------------

        //----------------------------------------------------------------------------
        /// <summary>
        /// Get/Set the optional test logic name
        /// </summary>
        public string TestName
        {
            get { return _testName; }
            set { _testName = value; }
        }

        //----------------------------------------------------------------------------
        /// <summary>
        /// Get/Set the optional test description
        /// </summary>
        public string TestDescription
        {
            get { return _testDescription; }
            set { _testDescription = value; }
        }

        //----------------------------------------------------------------------------
        /// <summary>
        /// Get/Set the target where the output reports must be written to
        /// </summary>
        public string OutputTarget
        {
            get { return _outputTarget; }
            set { _outputTarget = value; }
        }

        //----------------------------------------------------------------------------
        /// <summary>
        /// Get/Set the write mode of the output reports
        /// </summary>
        public NJC_TestPerformanceTargetWriteMode OutputTargetWriteMode
        {
            get { return _outputTargetWriteMode; }
            set { _outputTargetWriteMode = value; }
        }

        //----------------------------------------------------------------------------
        /// <summary>
        /// Get/Set the format of the output reports
        /// </summary>
        public NJC_TestPerformanceTargetFormat OutputTargetFormat
        {
            get { return _outputTargetFormat; }
            set { _outputTargetFormat = value; }
        }

        //----------------------------------------------------------------------------
        /// <summary>
        /// Get/Set the format used to generate the identification key of the output reports generated by this attribute
        /// </summary>
        public NJC_TestPerformanceTargetIdentificationFormat OutputTargetIdentificationFormat
        {
            get { return _outputTargetIdentificationFormat; }
            set { _outputTargetIdentificationFormat = value; }
        }

        //----------------------------------------------------------------------------
        /// <summary>
        /// Get/Set the target type
        /// </summary>
        public NJC_TestPerformanceTargetKind OutputTargetKind
        {
            get { return _outputTargetKind; }
            set { _outputTargetKind = value; }
        }

        //----------------------------------------------------------------------------
        #endregion
        //----------------------------------------------------------------------------

    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU Lesser General Public License (LGPLv3)


Written By
Software Developer (Senior) Dogma Solutions
Italy Italy
I'm a senior developer in .NET, COM & Win32 and I work for an Italian company involved in e-learning and competency-analisys systems.
My work is also my main hobby, and I spend a lot of my spare time writing tutorials and codes for video games and multimedia-related arguments.

Comments and Discussions