1

My Javascript Unit Testing Engine

by Alexandru Lungu 28. martie 2011 03:01

 

I’ve created this more than 5 years ago and from then I did very few modifications/addings to it.

The idea is simple – we have a test object that has methods that start with “test” word. I never pollute the global namespace with anything – including functions – so at the start individual/anonymous functions could not be added. Recently, I also added this feature.

It still remains with only one assert, $Test.ok – if its first parameter is false the test fails. I had in plan to implement others, but it was enough because it can simmulate all the others.

The example should explain how it should be used:

var MyTestObject = {
    testMethod1: function ()
    {
        $Test.ok(true, "True assert");
    },
    testMethod2: function ()
    {
        //Multiple asserts - al must be true in order for the test to pass.
        $Test.ok(true, "True assert");
        $Test.ok(false, "False assert");
    },
    name: "MyName",
    testName: function ()
    {
        this.changeName();
        $Test.ok(this.name == "MyName", this.name + "!=MyName");
    },
    changeName: function ()
    {
        this.name = "ChangedName";
    }
};

//adding a test object; all its methods that start with "test" will be executed
$Test.Add("My Test Object", MyTestObject);

//adding a test function and with the name "Func" for the test
$Test.Add("Func", function ()
{
    $Test.ok(5 == 4, "5==4");
});

//adding a test function with no name for the test
$Test.Add(function ()
{
    $Test.ok(5 == 5, "5==5");
});


//Runs all added functions and all functions that start with "test" from the added test objects
$Test.Run();
And this will produce the following output:

First are shown the anonymous functions (Test Object: Functions) and then the test methods from the test objects.

I know that it may appear rudimentary comparative to the actual unit testing frameworks like jsUnit, Screw.unit, js-test-driver, etc, but it did, and still does the job.

 

Download UnitTesting.js (5.52 kb)
Download Example.htm (1.70 kb)

Tags: ,

Programming

1

WCF Client Server Application with Custom Authentication, Authorization, Encryption and Compression

by Alexandru Lungu 23. martie 2011 23:52

 

About two weeks ago I published on CodeProject.com the article called WCF Client Server Application with Custom Authentication, Authorization, Encryption and Compression. 

It offers solution to this complex situation (very unlikely that you’ll have all these constraints):

- Client-server application – http protocol – NO IIS
- Authentication – user/password from a database – NO SSL/X509 certificate
- Authorization – roles from a database
- Encryption for the credentials (with option for the entire request/response)
- Compression for both the request and response.

It is in 2 parts, part 1 contains the logic, considerations about WCF and security, how to use the code. The second part contains explanations about the implementation.

I was surprised by the large numbers of views (more than 15.000), because there are few WCF readers compared with ASP.NET readers for example (this can be seen extremely well in the percentage of WCF monthly published articles on codeproject – about 1%).  Probably a big contribution had the fact that the article quickly became first on google and bing searches for wcf client server keywords (though I don’t know how long it will stay there).

Hence, the article had more than 60 codeproject bookmarks and more than 20 comments – most of the comments praising the organization and the explanations. And it ranked 5 (so far) in March popularity top (from about 400 articles).

I'm sure that 90% of the people that read this article won't use it in this form (all things combined together); some will use only the custom authentication/authorization; some the encryption and some the compression - as starting examples for their specific projects.

Tags:

News

Powered by BlogEngine.NET 2.0.0.36
Original Design by Laptop Geek, Adapted by onesoft