Alphan's Presentation in Mozilla

2015

  • Gaia Unit Test 101
  • Docker 101

Gaia Unit Test 101

2015.03.23

Where and How?

  • Where is the test file
    • e.g.  b2g/gaia/apps/camera/test/unit
    • *.js
  • How to run the test
    • under "b2g/gaia"

                        DEBUG=1 make; bin/gaia-test

a set of test

a test



suite('Storage()', function() {
	test(xxxx);
        test(xxxx);
        test(xxxx);
});


test('Should xxx ', function() {
	xxxx
});

The API library

  • Chai

    • http://chaijs.com/api/

    • Chai is a BDD / TDD assertion library for node and the browser that can be delightfully paired with any javascript testing framework.

  • Sinon.JS API

    • http://sinonjs.org/

    • Standalone test spies, stubs and mocks for JavaScript. No dependencies, works with any unit testing framework

Test spies

  • A test spy is a function that records arguments, return value, the value of this and exception thrown (if any) for all its calls.

  • A test spy can be an anonymous function or it can wrap an existing function.

  • When doing so, the original function will behave just as normal but you will have access to data about all calls.

Creating spies



var spy = sinon.spy();
// Creates an anonymous function

var spy = sinon.spy(myFunc); 
// Spies on the provided function

var spy = sinon.spy(object, "method");
/* Creates a spy for object.method and
     replaces the original method with the spy. 
   The original method can be restored 
     by calling object.method.restore(). */

Spy API

  • spy.called

    • Return true if the spy was called at least once

  • spy.calledOnce

    • Return true if spy was called exactly once.

    • More: spy.calledTwice

  • spy.calledWith(arg1, arg2, ...)

    • Returns true if spy was called at least once with the provided arguments

Test stubs

  • Test stubs are functions (spies) with pre-programmed behavior.

  • They support the full test spy API in addition to methods which can be used to alter the stub’s behavior.

  • As spies, stubs can be either anonymous, or wrap existing functions.

  • When wrapping an existing function with a stub, the original function is not called.

Creating Stubs



var stub = sinon.stub();
// Creates an anonymous stub function


var stub = sinon.stub(object, "method");
//Replaces object.method with a stub function.  
//object.method.restore(); (or stub.restore();


var stub = sinon.stub(object, "method", func);
// Replaces object.method with a func, wrapped in a spy. 

Stubs API



stub.returns(obj);	
// Makes the stub return the provided obj

stub.returnsArg(index);	
// stub.returnsArg(0); causes the stub to return the first argument.

stub.throws();		
// Causes the stub to throw an exception (Error).

stub.onCall(n);		
// stub.onFirstCall(); //stub.onCall(1)

stub.withArgs(arg1[, arg2, ...]); 
//Stubs the method only for the provided arguments.

Example



“test_withArgs”:function () {
    var callback = sinon.stub(); 
    callback.withArgs(42).returns(1);     
    callback.withArgs(1).throws("TypeError");

    callback(); // No return value, no exception 
    callback(42); // Returns 1 
    callback(1); // Throws TypeError
}

Example 2



"test should stub method with certain argument": function () { 
  var callback = sinon.stub(); 
  callback.withArgs(42) 
	.onFirstCall().returns(1) 
	.onSecondCall().returns(2); 
  callback.returns(0); 

  callback(1); // Returns 0 
  callback(42); // Returns 1 
  callback(1); // Returns 0 
  callback(42); // Returns 2 
  callback(1); // Returns 0 
  callback(42); // Returns 0
 } 

Real Example

Docker 101

2015.04.13

Outline

  • What is Docker?
  • Difference
  • Image & Container
  • Tutorial
  • Real Example : Raptor Local Visualization

What is Docker?

  • An open platform for developer and sysadmins to build, ship, and run distributed applications.
  • It based on lxc (linux container) and aufs.
  • Consisting of
    • Docker Engine, a portable, lightweight runtime

    • packaging tool

    • Docker Hub, a cloud service for sharing applications and automating workflows

       

Difference

Difference

Image & Container

  • Image is a initial environment. (e.g. CentOS)
    • There are lots of images in DockerHub by developers and companies
  • Container is a instance of executing this image
    • Can do anything in this container (install tomcat, JDK, …)
    • All behaviors are only in this container (which won’t effect the original image)

Turtorial

Raptor Local Visualization

  • Raptor Local Visualization
    • docker pull eliperelman/raptor
    • docker run -d -p 8080:8080 -p 8083:8083 -p 8086:8086 --expose 8090 --expose 8099 eliperelman/raptor:latest

 

Moz Presentation

By Alphan Chen

Moz Presentation

My presentation in Mozilla

  • 952