test-model-reporter

Create a pure JavaScript object model based on JUnit methodology

Test Model Reporter

JavaScript hierarchical object model
Any model type can validate, generate a report and write it to the file system
Currently JUnit xml and Jasmine reporters are supported:

  • JUnitGenerates JUnit XML files according to the junit.xsd
  • JasmineGenerates spec files

How To

First create a simple model

The model can be crated using an API like so:

var testcase,
    failure,
    testsuite = jmr.create({
        type: "model.testsuite",
        data: {
            name: "testsuite"
        }
    });
    testcase = jmr.create({
        type: "model.testcase",
        data: {
            time: "now"
        }
    });
    testcase.set("name", "This is the test name");

    failure = jmr.create({
        type: "model.failure",
        data: {
            message: "This is a faulire message",
            type: "failure"
        }
    });

    testcase.add(failure);
    testsuite.add(testcase);

With that:

You can create an HTML site using Ant Reporter.

// write your file to the tests folder
jmr.write("./tests/demoTest.xml", testsuite.compile());

// tell ant where are your tests and where to put your HTML output
// Ant will collect all your *Test.xml files from test folder
jmr.report({
        reportsdir: "tests/reports",
        testsdir: "tests"
    });

Note: Ant dependency is not installed. You can find it in the dev dependency section.

Another example

In case you generates an object with all of your data, much simpler to burst it like so:

var obj = jmr.generate({
    type: "model.testsuites",
    data: {
        disabled: "false",
        name: "test.suites",
        body: [{
            type: "model.testsuite",
            data: {
                id: "$id",
                package: "test.test",
                name: "test.suite.1",
                body: [{
                    type: "model.testcase",
                    data: {
                        classname: "class1",
                        name: "test.case",
                        time: "now",
                        body: [{
                            type: "model.failure",
                            data: {
                                type: "fail",
                                body: "body content in here..."
                            }
                        }]
                    }
                }]
            }
        }]
    }
});

Jasmine example

Note: to be able to test the specs using node run: node installer.js or install jasmine-node module.

tmr.setReporter("jasmine");

var describe = tmr.create({
    type: "model.jas.describe",
    data: {
        title: "A suite is just a function",
        body:[
            {
                type:"model.jas.code",
                data: {
                    body: "var a;"
                }
            },
            {
                type: "model.jas.it",
                data: {
                    title: "and so is a spec",
                    body: [{
                        type:"model.jas.code",
                        data: {
                            body: "a = true; expect(a).toBe(true);"
                        }
                    }]
                }
            }
        ]
    }
});        


Model types: 
* **model.jas.describe** describe method
* **model.jas.it** it method
* **model.jas.code** code snippet 

Note: WIP, other Jasmine functionality will be supported.

Browser Support

Usage

  • AMD

    • See tmrwebRequire-min.js file, as an example of requirejs project style

      define([], function() {

      var jmrOnReady = function (jmr) {
            // use the "jmr" object   
        };
        return jmrOnReady;

      });

  • None AMD

    // Use "jmr" or "testModelReporter" objects 

Download

+ AMD
    + [tmr-require-min.js](https://raw.github.com/lastboy/test-unit-reporter/master/target/tmr-require-min.js)    

Troubleshooting

  • Ant reporter, issue with MAC
    • After Ant Npm installed edit the ../bin/ant file according to the following fix

Reference


Create a specific entity according to a given configuration

  • create(config)
    • config {Object} The JUnit based configuration model
      • type - The type of the class model.[testsuites | testsuite | testcase | failure | error | skipped | system]
      • data - The class data
        • available specification properties (id, name, disabled, etc...)
        • body - the class children, can be a nested class or a string value

Generate an object model according to a given configuration

  • generate(config)
    • config {Object} The JUnit based configuration model
      • type - The type of the class model.[testsuites | testsuite | testcase | failure | error | skipped | system]
      • data - The class data
        • available specification properties (id, name, disabled, etc...)
        • body - the class children, can be a nested class or a string value return an object
    • output {String} The generate output model
    • model {Object} The generated object model

Generate a report (if supported by the reporter)

* report(config) + config {Object} The configuration to be passed to the reporter

JUnit Reporter configuration {reportsdir: "the output report location", testsdir: "the test folder to be scanned"}

Write your data to a file

* write(file, data) + file {String} The file + data {String} The file content

Set the reporter type

* setReporter(key) + key {String} The key name of the reporter (currently "junit" (default) supported only)

Contribute

This package can be extended to support additional reporters.

* Create a folder name based on your reporter name e.g. ./src/reporter/dot * Create a templates folder below your reporter root folder * With Mustache syntax create your templates including the incoming data * Implement Reporter.js class + implement report method (optional)

See ./src/reporter/junit and ./src/reporter/jasmine reporters for more information

HomePage

https://github.com/lastboy

Repository

https://github.com/lastboy/test-unit-reporter


上一篇:package-script
下一篇:locks

相关推荐

  • 逻辑强化系列(一):彻底搞懂自定义组件使用 v-model

    前言 阅读本文前,希望你已经彻底理解了语法糖 vmodel 以及父子组件之间的通讯方法 vmodel 在组件上使用 vmodel 之前首先要知道,vmodel 的用处以及实际操作流程,以方便理解,而不...

    3 个月前
  • 要如何在Viewer脱机模式下使用加载 AEC Model Data?

    近期有在关注 Forge 的朋友应该有注意到 Forge Viewer 终于推出原生的楼层剖切扩展 (Autodesk.AEC.LevelsExtension) 和小地图扩展 (Autodesk.AE...

    5 个月前
  • 自定义组件v-model的最简洁实现 - 基础篇

    在日常的开发中,自定义一个支持双向绑定的组件是非常常见的应用场景,而官方文档(https://cn.vuejs.org/v2/guide/componentscustomevents.html%E8%...

    1 年前
  • 简述JavaScript的正则表达式中test()方法的使用

    test方法为正则表达式匹配的文本搜索字符串。如果找到匹配,则返回true; 否则返回false。 语法 下面是参数的详细信息: 返回值: 例子: 这将...

    3 年前
  • 简析CSS盒模型(Box Model)

    CSS 盒子模型(Box Model) 每个HTML元素都可以看作是一个盒子,封装周围的HTML元素,它包括:外边距(margin)、边框(border)、内边距(padding)、实际内容(cont...

    1 个月前
  • 用表单项和v-model实现简单的双向绑定

    Vue采用的是数据劫持和发布订阅相结合的方式实现双向绑定,数据劫持主要通过Object。defineProperty来实现。举一个关于defineProperty的简单例子: 通过上述操作,...

    3 个月前
  • 父子组件传值及v-model实现通信

    一. 父组件向子组件传值 1. 创建parent和child组件,并在parent中注册child组件 2. 在父组件调用子组件标签中添加一个自定义属性(msg), 1. 在子组件的p...

    1 年前
  • 深入解析Vue.js中v-bind v-model的使用和区别

    vmodel 指令在表单控件元素上创建双向数据绑定,所谓双向绑定,指的就是我们在js中的vue实例中的data与其渲染的dom元素上的内容保持一致,两者无论谁被改变,另一方也会相应的更新为相同的数据 ...

    2 年前
  • 深入理解Div和CSS的布局layout盒模型Box Model

    熟练掌握Div和CSS的布局(layout)方法,首先要对盒模型(Box Model)有足够的了解。盒子模型是CSS布局网页时非常重要的概念,只有很好地掌握了盒子模型以及其中每个元素的使用方法,才能熟...

    8 个月前
  • 浅谈regExp的test方法取得的值变化的原因及处理方法

    1、JavaScript 正则表达式对象RegExp的test方法,用于检测一个字符串是否匹配某个模式。 字面量定义RegExp对象:var re = /pattern/attributes,其中a...

    3 年前

官方社区

扫码加入 JavaScript 社区