Justmock Lite (Free Mocking Framework for. NET)

Source: Internet
Author: User

    1. Install through Nuget

2. Download the website (the official website does not point here)

3. Help documentation

Business Edition and Free Edition difference overview

Mockingcontainer

Test class Preparation: Generally, it is also a business class

    public class Classundertest    {        private ifirstdependency firstdep;        Private iseconddependency SECONDDEP;        Public Classundertest (ifirstdependency first, iseconddependency second)        {            THIS.FIRSTDEP = first;            THIS.SECONDDEP = second;        }        Public ilist<object> Collectionmethod ()        {            var firstcollection = Firstdep.getlist ();            return firstcollection;        }        public string Stringmethod ()        {            var secondstring = seconddep.getstring ();            return secondstring;        }    }    Public interface ifirstdependency    {        ilist<object> GetList ();    }    Public interface iseconddependency    {        string GetString ();    }

  Unit Test

        [TestMethod] public void Shouldmockdependencieswithcontainer () {//ARRANGE//             Creating a mockingcontainer of classundertest. To instantiate the system Uder test (the container) your should use the Instance property//For Example:co Ntainer.             Instance.            var container = new mockingcontainer<classundertest> ();            String expectedstring = "Test"; Arranging:when the GetString () method from the Iseconddependecy interface//was called from T             He container, it should return expectedstring. Container. Arrange<iseconddependency> (SECONDDEP = seconddep.getstring ()).            Returns (expectedstring); Act-calling Sringmethod () from the mocked instance of classundertest var actualstring = container.            Instance.stringmethod ();        ASSERT assert.areequal (expectedstring, actualstring); }

It is important to note that the Mockingcontainer constructor has an optional parameter, automocksettings, where automocksettings one of the main functions is when classundertest has more than one constructor, Specify the appropriate constructor to instantiate the object

When there is a parameterless constructor in the business class, a parameterless constructor is executed by default without setting automocksettings,

You can specify the required constructors as follows

        Automocksettings settings = new Automocksettings            {                constructorargtypes = new type[]{                  typeof ( Ifirstdependency), typeof (Iseconddependency)                }            };            ARRANGE            //Creating a mockingcontainer of classundertest.             To instantiate the system Uder test (the container) your should use the Instance property             //For Example:container . Instance.             var container = new mockingcontainer<classundertest> (settings);

  

Justmock Lite (Free Mocking Framework for. NET)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.