Pitesti: A Super-simple JavaScript Test Framework

PITESTI

pitesti is a tiny but useful test framework for Node.js. Node 12.x and higher are supported.

You can also use pitesti in browsers. See below for details.

GOALS

  • Only output TAP.
  • Allow just about anything to be passed in as a "test". For example:
    • A function that either throws or doesn't.
    • A function taking a nodeback/errback, where the error indicates test fail.
    • A promise (whose result is assumed by the test).
    • A function returning a promise (whose result is assumed by the test).
  • Super-simple test definition format.
  • No setup or teardown functions (except in BDD mode).

USAGE

First, create a test suite.

const test = require('pitesti')();

pitesti exports a single function which creates test suites. It takes in an options object (or nothing) with the following values:

  • outputStream: where to write TAP output. Default is process.stdout.
  • summary: whether or not to write a summary to the outputStream and the end of testing. Default is true.
  • timeout: Milliseconds after which to fail the test if it hasn't passed yet. Default is 5000. See "Timeouts" below.
  • contextSeparator: String used to separate context names from test names. Default is ' '.
  • done: a callback function that will take in an exit code. Default is process.exit.

Now you can write some tests and run them.

const test = require('pitesti')();

// any function returning a promise can be a test
test('foo example test 1', function(){
  return Promise.resolve();
});

// a failing test is one that returns a (eventually) rejecting promise
test('foo example test 2', function(){
  return Promise.reject(new Error('bad'));
});

// async functions also work just fine!
test('foo example test 3', async function(){
  await something();
});

// if you already have some promises lying around, you can pass those in
let myPromise = Promise.resolve();
test('foo example test 4', myPromise);

// you can call test as a template literal, for a fun DSL
test `foo example test 5` (() => Promise.resolve('good'));

// you can also have tests that just call a callback or throw
test `foo example test 6` (cb => {
  maybeThrow();
  maybeCallBackWithError(cb);
});

// this starts running the suite
test();

This will run the tests, outputting to the outputStream, and when done will call done, so in this example it will print the following to stdout and then exit.

TAP version 13
1..3
ok 1 foo example 1
not ok 2 foo example 2
  ---
  name: Error
  message: bad
  stack: |-
    Error: bad
      <stacktrace line 1>
      <stacktrace line 2>
      <stacktrace line 3>
      <...>
  ...
ok 3 foo example 3
ok 3 foo example 4

Since one of the tests failed, the exit code is 1, rather than the 0 we'd get in a 100% success case.

Assertions

You can use whatever assertion library you want, provided that you return a Promise whose end-result passes or fails the test, or just simply throw. Pretty much every assertion library falls under this, so you should be fine.

Skip and Only

You can skip or isolate a test the same way you would in Mocha. The template literal forms work as with just test.

test.only('only this test will run', function(){
    // ...
});
test.skip('all tests except this one will run', function(){
    // ...
});

Timeouts

By default, each test case has a time limit of 5000ms, after which the test will be considered a failure.

You can set a global timeout for an entire test suite using the options object as described above. You can also pass a third argument to the test function that is an options object containing a timeout option, in order to set a timeout for a specific test:

test('this is a test with a 1 second timeout', () => {
  // ...
}, { timeout: 1000 });

To completely disable timeouts, you can set a timeout property to Infinity.

Multiple Files

Pitesti isn't designed with files in mind. That means you're free to do whatever you want.

There are two main suggested approaches to take:

  1. Write test files as functions taking in the test suite function, and then pass that in to each module from a main test file.
  2. Use a tool like the node-tap cli to run all your test files as individual suites.

Grouping, Contexts

You can add a layer of context to tests by using test.context:

test.context('MyClass', () => {
  test('foo', () => { /* ... */ });
  test('bar', () => { /* ... */ });
});

You can do this up to an arbitrary depth.

You can change the separator used in the TAP output by using the contextSeparator option as defined above.

Mocha/BDD Syntax

A BDD-style interface is provided, exported as pitesti/bdd. The exported functions are as follows, with the effectively the same functionality as Mocha.

  • describe
  • context
  • it
  • before
  • beforeAll (same as before)
  • beforeEach
  • after
  • afterAll (same as after)
  • afterEach

If you'd like these as globals, you can do something like this.

Object.assign(global, require('pitesti/bdd'));

Note that Mocha's this object is not supported. Instead, to configure an individual test for timeouts, add an extra parameter to the it function, much like the test function in regular Pitesti.

For example:

it('does a thing', () => {
  // ... some slow code ...
}, { timeout: 10000 });

Much like with Mocha, you don't need to initiate the test suite. It will run on its own in a nextTick. Unlike Mocha, you cannot add additional test cases dynamically after the first tick.

NOTE: pitesti/bdd does not currently work in browsers.

Browser Usage

Pitesti can be used in a browser environment via webpack, browserify, or other web packaging tools.

You'll have to set an outputStream, so if you're using one of the tools above, you should be able to do something like:

const pitesti = require('pitesti');
const { Writable } = require('stream');
const out = document.getElementById('test-output');
const outputStream = new Writable({
  write(chunk, encoding, cb) {
    out.innerHTML += chunk;
    cb();
  }
});
const test = pitesti({ outputStream });

Caveats

  • Pitesti runs tests sequentially. While running in "parallel" might sound better, in reality, many real-world tests involve singletons and other global state that's changed throught the course of a single test. It's far easier to reason about what's going on if only one test can be causing an error at any given time.
  • If your code fails to examine errors in errbacks/nodebacks, or does not handle promise rejections, you may find that these errors are invisible. The position taken by Pitesti is that if you're ignoring an error, you don't care that it's an error, and it's not a problem for your code.

Author: bengl
Source Code: https://github.com/bengl/pitesti 
License: MIT license

#node #javascript #testing #framework 

What is GEEK

Buddha Community

Pitesti: A Super-simple JavaScript Test Framework
Joseph  Murray

Joseph Murray

1621492530

7 Test Frameworks To Follow in 2021 for Java/Fullstack Developers

It is time to learn new test frameworks in 2021 to improve your code quality and decrease the time of your testing phase. Let’s explore 6 options for devs.

It is time to learn new test frameworks to improve your code quality and decrease the time of your testing phase. I have selected six testing frameworks that sound promising. Some have existed for quite a long time but I have not heard about them before.

At the end of the article, please tell me what you think about them and what your favorite ones are.

Robot Framework

Robot Framework is a generic open-source automation framework. It can be used for test automation and robotic process automation (RPA).

Robot Framework is open and extensible and can be integrated with virtually any other tool to create powerful and flexible automation solutions. Being open-source also means that Robot Framework is free to use without licensing costs.

The RoboFramework is a framework** to write test cases and automation processes.** It means that it may replace** your classic combo Selenium + Cucumber + Gherkins**. To be more precise, the Cucumber Gherkins custom implementation you wrote will be handled by RoboFramework and Selenium invoked below.

For the Java developers, this framework can be executed with Maven or Gradle (but less mature for the latter solution).

#java #testing #test #java framework #java frameworks #testing and developing #java testing #robot framework #test framework #2021

Top 15 Free JavaScript Frameworks for Web Applications

List of some useful JavaScript Frameworks and libraries for website, web apps, and mobile apps development, that developers should know about to make selection easier.
This article will help you understand the various types of JavaScript Framework available in the market. When it comes to choosing the best platform for you, it’s not only the number of features you need to consider but also its functionality. The ease with which it fits within your project is also an essential factor. The next step is to choose the framework that best fits your company requirements or you can select the best from the list of top web development companies to develop your product based on your requirements.

#javascript frameworks for web applications #web applications development companies #progressive javascript framework #javascript frameworks #javascript #frameworks

Lindsey  Koepp

Lindsey Koepp

1598948520

Top 10 Test Automation Frameworks in 2020

We are moving toward a future where everything is going to be autonomous, fast, and highly efficient. To match the pace of this fast-moving ecosystem, application delivery times will have to be accelerated, but not at the cost of quality. Achieving quality at speed is imperative and therefore quality assurance gets a lot of attention. To fulfill the demands for exceptional quality and faster time to market, automation testing will assume priority. It is becoming necessary for micro, small, and medium-sized enterprises (SMEs) to automate their testing processes. But the most crucial aspect is to choose the right test automation framework. So let’s understand what a test automation framework is.

What Is a Test Automation Framework?

A test automation framework is the scaffolding that is laid to provide an execution environment for the automation test scripts. The framework provides the user with various benefits that help them to develop, execute, and report the automation test scripts efficiently. It is more like a system that was created specifically to automate our tests. In a very simple language, we can say that a framework is a constructive blend of various guidelines, coding standards, concepts, processes, practices, project hierarchies, modularity, reporting mechanism, test data injections, etc. to pillar automation testing. Thus, the user can follow these guidelines while automating applications to take advantage of various productive results.

The advantages can be in different forms like the ease of scripting, scalability, modularity, understandability, process definition, re-usability, cost, maintenance, etc. Thus, to be able to grab these benefits, developers are advised to use one or more of the Test Automation Framework. Moreover, the need for a single and standard Test Automation Framework arises when you have a bunch of developers working on the different modules of the same application and when we want to avoid situations where each of the developers implements his/her approach towards automation. So let’s have a look at different types of test automation frameworks.

Types of Automated Testing Frameworks

Now that we have a basic idea about Automation Frameworks, let’s check out the various types of Test Automation Frameworks available in the marketplace. There is a divergent range of Automation Frameworks available nowadays. These frameworks may differ from each other based on their support to different key factors to do automation like reusability, ease of maintenance, etc.

Types of Test Automation Frameworks:

  1. Module Based Testing Framework
  2. Library Architecture Testing Framework
  3. Data-Driven Testing Framework
  4. Keyword Driven Testing Framework
  5. Hybrid Testing Framework
  6. Behavior Driven Development Framework

Benefits of a Test Automation Framework

Apart from the minimal manual intervention required in automation testing, there are many advantages of using a test automation framework. Some of them are listed below:

  1. Faster time-to-market: Using a good test automation framework helps reduce the time-to-market of an application by allowing constant execution of test cases. Once automated, the test library execution is faster and runs longer than manual testing.
  2. Earlier detection of defects: The documentation of software defects becomes considerably easier for the testing teams. It increases the overall development speed while ensuring correct functionality across areas. The earlier a defect is identified, the more cost-effective it is to resolve the issue.
  3. Improved Testing efficiency: Testing takes up a significant portion of the overall development lifecycle. Even the slightest improvement of the overall efficiency can make an enormous difference to the entire timeframe of the project. Although the setup time takes longer initially, automated tests eventually take up a significantly lesser amount of time. They can be run virtually unattended, leaving the results to be monitored toward the end of the process.
  4. Better ROI: while the initial investment may be on the higher side, automated testing saves organizations many a lot of money. This is due to the drop in the amount of time required to run tests, which leads to a higher quality of work. This in turn decreases the necessity for fixing glitches after release, thereby reducing project costs.
  5. Higher test coverage: In test automation, a higher number of tests can be executed about an application. This leads to higher test coverage, which is a manual testing approach that would imply a massive team, limited heavily with their amount of time. An increased test coverage leads to testing more features and a better quality of the application.
  6. Reusability of automated tests: The repetitive nature of test cases in test automation helps software developers to assess program reaction, in addition to the relatively easy configuration of their setup. Automated test cases can be utilized through different approaches as they are reusable.

#devops #testing #software testing #framework #automation testing #mobile app testing #test framework

Pitesti: A Super-simple JavaScript Test Framework

PITESTI

pitesti is a tiny but useful test framework for Node.js. Node 12.x and higher are supported.

You can also use pitesti in browsers. See below for details.

GOALS

  • Only output TAP.
  • Allow just about anything to be passed in as a "test". For example:
    • A function that either throws or doesn't.
    • A function taking a nodeback/errback, where the error indicates test fail.
    • A promise (whose result is assumed by the test).
    • A function returning a promise (whose result is assumed by the test).
  • Super-simple test definition format.
  • No setup or teardown functions (except in BDD mode).

USAGE

First, create a test suite.

const test = require('pitesti')();

pitesti exports a single function which creates test suites. It takes in an options object (or nothing) with the following values:

  • outputStream: where to write TAP output. Default is process.stdout.
  • summary: whether or not to write a summary to the outputStream and the end of testing. Default is true.
  • timeout: Milliseconds after which to fail the test if it hasn't passed yet. Default is 5000. See "Timeouts" below.
  • contextSeparator: String used to separate context names from test names. Default is ' '.
  • done: a callback function that will take in an exit code. Default is process.exit.

Now you can write some tests and run them.

const test = require('pitesti')();

// any function returning a promise can be a test
test('foo example test 1', function(){
  return Promise.resolve();
});

// a failing test is one that returns a (eventually) rejecting promise
test('foo example test 2', function(){
  return Promise.reject(new Error('bad'));
});

// async functions also work just fine!
test('foo example test 3', async function(){
  await something();
});

// if you already have some promises lying around, you can pass those in
let myPromise = Promise.resolve();
test('foo example test 4', myPromise);

// you can call test as a template literal, for a fun DSL
test `foo example test 5` (() => Promise.resolve('good'));

// you can also have tests that just call a callback or throw
test `foo example test 6` (cb => {
  maybeThrow();
  maybeCallBackWithError(cb);
});

// this starts running the suite
test();

This will run the tests, outputting to the outputStream, and when done will call done, so in this example it will print the following to stdout and then exit.

TAP version 13
1..3
ok 1 foo example 1
not ok 2 foo example 2
  ---
  name: Error
  message: bad
  stack: |-
    Error: bad
      <stacktrace line 1>
      <stacktrace line 2>
      <stacktrace line 3>
      <...>
  ...
ok 3 foo example 3
ok 3 foo example 4

Since one of the tests failed, the exit code is 1, rather than the 0 we'd get in a 100% success case.

Assertions

You can use whatever assertion library you want, provided that you return a Promise whose end-result passes or fails the test, or just simply throw. Pretty much every assertion library falls under this, so you should be fine.

Skip and Only

You can skip or isolate a test the same way you would in Mocha. The template literal forms work as with just test.

test.only('only this test will run', function(){
    // ...
});
test.skip('all tests except this one will run', function(){
    // ...
});

Timeouts

By default, each test case has a time limit of 5000ms, after which the test will be considered a failure.

You can set a global timeout for an entire test suite using the options object as described above. You can also pass a third argument to the test function that is an options object containing a timeout option, in order to set a timeout for a specific test:

test('this is a test with a 1 second timeout', () => {
  // ...
}, { timeout: 1000 });

To completely disable timeouts, you can set a timeout property to Infinity.

Multiple Files

Pitesti isn't designed with files in mind. That means you're free to do whatever you want.

There are two main suggested approaches to take:

  1. Write test files as functions taking in the test suite function, and then pass that in to each module from a main test file.
  2. Use a tool like the node-tap cli to run all your test files as individual suites.

Grouping, Contexts

You can add a layer of context to tests by using test.context:

test.context('MyClass', () => {
  test('foo', () => { /* ... */ });
  test('bar', () => { /* ... */ });
});

You can do this up to an arbitrary depth.

You can change the separator used in the TAP output by using the contextSeparator option as defined above.

Mocha/BDD Syntax

A BDD-style interface is provided, exported as pitesti/bdd. The exported functions are as follows, with the effectively the same functionality as Mocha.

  • describe
  • context
  • it
  • before
  • beforeAll (same as before)
  • beforeEach
  • after
  • afterAll (same as after)
  • afterEach

If you'd like these as globals, you can do something like this.

Object.assign(global, require('pitesti/bdd'));

Note that Mocha's this object is not supported. Instead, to configure an individual test for timeouts, add an extra parameter to the it function, much like the test function in regular Pitesti.

For example:

it('does a thing', () => {
  // ... some slow code ...
}, { timeout: 10000 });

Much like with Mocha, you don't need to initiate the test suite. It will run on its own in a nextTick. Unlike Mocha, you cannot add additional test cases dynamically after the first tick.

NOTE: pitesti/bdd does not currently work in browsers.

Browser Usage

Pitesti can be used in a browser environment via webpack, browserify, or other web packaging tools.

You'll have to set an outputStream, so if you're using one of the tools above, you should be able to do something like:

const pitesti = require('pitesti');
const { Writable } = require('stream');
const out = document.getElementById('test-output');
const outputStream = new Writable({
  write(chunk, encoding, cb) {
    out.innerHTML += chunk;
    cb();
  }
});
const test = pitesti({ outputStream });

Caveats

  • Pitesti runs tests sequentially. While running in "parallel" might sound better, in reality, many real-world tests involve singletons and other global state that's changed throught the course of a single test. It's far easier to reason about what's going on if only one test can be causing an error at any given time.
  • If your code fails to examine errors in errbacks/nodebacks, or does not handle promise rejections, you may find that these errors are invisible. The position taken by Pitesti is that if you're ignoring an error, you don't care that it's an error, and it's not a problem for your code.

Author: bengl
Source Code: https://github.com/bengl/pitesti 
License: MIT license

#node #javascript #testing #framework 

Abigale  Yundt

Abigale Yundt

1603336938

What Will Be The Best JavaScript Frameworks in 2021? -

Someone who is beginning their work journey as a developer or software engineer might encounter an issue while selecting which language, framework, or tools they should be trained in or must have knowledge about. A lot of individuals had to go through such a scenario. Since there is a large range of languages and frameworks available in the software development community, there is not a single solution or option. Hence, we have created this list to narrow down your option. In this post, we will talk about various _ JavaScript Frameworks_ that we feel will be the most useful in 2021.

When we are talking about the development of websites, the JavaScript framework comes in the mind quickly for companies and programmers in today’s world. You most likely had a chance to work on one or two of the JavaScript Frameworks that we have mentioned on the list. Go on and learn more about these JavaScript Frameworks.

1. ReactJS

React is the most prominent JS framework since it was launched by Facebook in 2003. The potential to utilize it for native development comes amongst the key benefits of React. A broad community, Facebook support, saturated environments, improved efficiency, and reusable components are the key reasons behind React’s success. React is ideally suited for building SPA or cross-platform applications and designing small business applications.

ReactJS

#javascript #frameworks #javascript #javascript frameworks #mobile application