All Projects → adobe → mocka

adobe / mocka

Licence: Apache-2.0 license
Mocka - The complete testing framework for LUA and Nginx

Programming Languages

javascript
184084 projects - #8 most used programming language
lua
6591 projects
CSS
56736 projects
HTML
75241 projects
shell
77523 projects
Dockerfile
14818 projects

Projects that are alternatives of or similar to mocka

mock
Utilities to help mock behavior, spy on function calls, stub methods, and fake time for tests.
Stars: ✭ 31 (+19.23%)
Mutual labels:  mock, stub, spy
phake
PHP Mocking Framework
Stars: ✭ 464 (+1684.62%)
Mutual labels:  mock, stub, spy
Wiremockui
Wiremock UI - Tool for creating mock servers, proxies servers and proxies servers with the option to save the data traffic from an existing API or Site.
Stars: ✭ 38 (+46.15%)
Mutual labels:  mock, stub
Mocha
Mocha is a mocking and stubbing library for Ruby
Stars: ✭ 1,065 (+3996.15%)
Mutual labels:  mock, stub
Impersonator
Ruby library to record and replay object interactions
Stars: ✭ 100 (+284.62%)
Mutual labels:  mock, stub
Swiftmockgeneratorforxcode
An Xcode extension (plugin) to generate Swift test doubles automatically.
Stars: ✭ 522 (+1907.69%)
Mutual labels:  mock, stub
Ohhttpstubs
Stub your network requests easily! Test your apps with fake network data and custom response time, response code and headers!
Stars: ✭ 4,831 (+18480.77%)
Mutual labels:  mock, stub
Cuckoo
Boilerplate-free mocking framework for Swift!
Stars: ✭ 1,344 (+5069.23%)
Mutual labels:  mock, stub
stub-server
Stub server for REST APIs
Stars: ✭ 14 (-46.15%)
Mutual labels:  mock, stub
Mockit
A tool to quickly mock out end points, setup delays and more...
Stars: ✭ 1,534 (+5800%)
Mutual labels:  mock, stub
Mockery
Mockery is a simple yet flexible PHP mock object framework for use in unit testing with PHPUnit, PHPSpec or any other testing framework. Its core goal is to offer a test double framework with a succinct API capable of clearly defining all possible object operations and interactions using a human readable Domain Specific Language (DSL).
Stars: ✭ 10,048 (+38546.15%)
Mutual labels:  mock, stub
Spy
Clojure/ClojureScript library for stubs, spies and mocks.
Stars: ✭ 131 (+403.85%)
Mutual labels:  mock, stub
Hippolyte
HTTP Stubbing in Swift
Stars: ✭ 109 (+319.23%)
Mutual labels:  mock, stub
Dyson
Node server for dynamic, fake JSON.
Stars: ✭ 814 (+3030.77%)
Mutual labels:  mock, stub
DeepfakeHTTP
DeepfakeHTTP is a web server that uses HTTP dumps as a source for responses.
Stars: ✭ 373 (+1334.62%)
Mutual labels:  mock, stub
Timex
A test-friendly replacement for golang's time package
Stars: ✭ 53 (+103.85%)
Mutual labels:  mock, stub
Wasmite
Now WebAssembly has proper testing, unit-testing and debugging 🤗
Stars: ✭ 20 (-23.08%)
Mutual labels:  debugger, testing-framework
Stubmatic
Mock HTTP calls without coding. Designed specially for testing and testers.
Stars: ✭ 118 (+353.85%)
Mutual labels:  mock, stub
deckard
DNS test harness
Stars: ✭ 28 (+7.69%)
Mutual labels:  mock, testing-framework
Mimic
A mocking library for Elixir
Stars: ✭ 104 (+300%)
Mutual labels:  mock, stub

Testing Framework for Lua - Mocka Build Status Coverage Status

The one lua testing framework that mocks classes, runs with real classes from your project, has nginx embedded methods for openresty individual testing. Has a suite of libraries preinstalled and you can specify libraries to install.

Mocka runs better in docker than in standalone - all you need to do is pull the image and run it like so

Table of contents

  1. Installing
  2. Running
    1. Run with docker
  3. Usage inside test classes
    1. Mocking
    2. Running and skipping tests
    3. Assertions
  4. Dependencies
  5. Contributing

Installing

  • sudo luarocks make mocka-1.0.0-1.rockspec
  • sudo luarocks install luacov

Optional:

  • lua -lluacov run_tests.lua
  • luacov
  • luacov-cobertura -o coverage_report.xml

Suggest using:

GitHub Pull Request Coverage Status and Cobertura Plugin

Running

  • mocka <path_to_file> - run a test file written in mocka framework style
  • mocka -t <path_to_file> - run a test file written in mocka framework style (you can pass multiple -t files and the command will run all)
  • mocka <path_to_file> -p <path_to_root_of_project> - run a test file and set the project root to the directory provided in -p (this helps a lot when working with packages). !The path to root of project is more or less the same as for your luarocks module - where your lua files are all located!

If you need coverage report in a human readable form:

   luacov
   luacov-cobertura -o coverage_report.xml

Run with docker

Build docker image and tag it with latest

make build-docker 

Run unit tests

make run-tests

Build docker image and run unit tests on local machine

make build-and-test 

Usage inside test classes

spy(...) - spying and stubbing

Spy whatever classes you want. Spies are reset after each test. And loose whatever stubbing you did. That is why if any stub is needed than it should be declared at beforeEach level. T2 is a global required field in this example - required somewhere else.

Stubs treat even the async nature of nginx - ran on demand

    beforeEach(function()
        spy("test2", "run", function()
            print "Ok"
        end)
    end)
    test('it is', function()
        t2:run()
        calls(spy("test2").run, 1)
    end)

mock(...) - Mocking

Mock whatever methods you want. Mocks are reset after each test. And loose whatever stubbing you did. That is why if any stub is needed than it should be declared at beforeEach level or test level.

    local classToMock = mock("path.to.class", {"method1", "method2"})

or mock all the methods dynamic

    local classToMock = mock("path.to.class")

Alter mock behaviour

    local classToMock = mock("path.to.class", {"method1", "method2"})
    when(classToMock).method1.fake(function(arg1, arg2)
        return arg1
    end)

or

    local classToMock = mock("path.to.class", {"method1", "method2"})
    when(classToMock).method1.doReturn = function(arg1, arg2)
            return arg1
    end

or

    local classToMock = mock("path.to.class", {"method1", "method2"})
    classToMock.__method1.doReturn = function(arg1, arg2)
        return arg1
    end

The only method that you don't want to alter if you mock is the new function.

test(...) and xtest(...) - Running and Skipping

Running a test

    test('describe what you are testing', function()
        assertEquals(true, true)
    end)

Running a test that throws exception or you know it will fail

    test('describe what you are testing', function()
        assertEquals(true, false)
    end, true)

Skipping a test

    xtest('describe what you are testing', function()
        assertEquals(true, true)
    end)

Assertions

assertEquals

    assertEquals(true, true)
    local one_object = {
        one = 1,
        two = 2
    }
    local second_object = {
        two = 2,
        one = 1
    }
    
    assertEquals(one_object, second_object)
    assertEqualse("string", "string")
    assertEquals(1,1)
    local first_array = {1, 2, 3}
    local second_array = {1, 2, 3}
    assertEquals(first_array, second_array)

assertNotEquals

    local first_array = {1, 2, 3}
    local second_array = {2, 1, 3}
    assertNotEquals(first_array, second_array)

assertNil

    assertNil(x)

assertNotNil

    local x = "string"
    assertNotNil(x)

assertTrue

    local x = 3 < 5
    assertTrue(x)

assertFalse

    local x = 3 > 5
    assertFalse(x)

calls(...) - verify a mock has been called

    local classToMock = mock("class", {"method"})
    calls(classToMock.__method, 1)
    local classToMock = mock("class", {"method"})
    calls(classToMock.__method, 1, arg2, arg1)

Dependencies

This dependencies apply for docker

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].