Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

Introduction to Ember testing


May 09, 2021 Ember.js Reference documents


Table of contents


Original English: Https://guides.emberjs.com/v2.7.0/testing/

Introduction to the test

The test is Ember。js part of the js framework development process.

Now suppose you're using the Ember framework to develop a blog system user post with login and blog creation. Finally, suppose you want to automate testing in your program.

The type of test

You'll need the following three types of tests:

  1. Acceptance testIngAcceptance
  2. Unit test Unit
  3. Integration testing Integration

Acceptance Tests

Acceptance testing is a test that ensures that the program process is correct and that the various interaction characteristics are in line with user expectations.

Acceptance testing is used to confirm the basic functions of the project, to ensure that the core functions of the project are not degraded, and to ensure that the objectives of the project are achieved. The way you test your app is consistent with how users interact with it (e.g., filling out a form, clicking a button).

In the above scenario, the following acceptance tests may be performed:

  1. Users can sign in through the sign-in form.
  2. Users can create blogs.
  3. When a blog post is successfully saved, the program returns the blog list to the user.
  4. Visitors cannot access the management interface.

Unit Tests

Unit tests are tests that are performed on the smallest testable unit in a program, such as a class or a method. The test can write statements relative to the program logic to test the relevant units

Here are some concrete examples of unit tests:

  1. The user's name is a combination of the corresponding last name and first name.
  2. Convert the blog request data correctly serialized into a blog model object.
  3. Format the blog time correctly.

Integrated testing Integration Tests

Integration testing is a test that is between unit testing and acceptance testing. The purpose of integrated testing is to verify that the client interacts with the system as a whole, that all unit tests, and the algorithmic logic of specific code at the micro level can pass.

Integration testing is used to verify the relationship between the various modules of an application, such as the behavior of several UI controls. I t can also be used to confirm that data and actions are correctly passed and executed in different parts of the system, while providing the conditions under which the various components of the system operate in conjunction under a given assumption.

We recommend that each component be tested for integration because each component of the component runs in the same way in the context of the system, and there is an impact between the components, including rendering the component from the template and receiving component lifecycle callback functions.

An example of integration testing is as follows:

  1. The user's name and date are displayed correctly on each blog post
  2. Users are prohibited from entering more than 50 characters in the title bar
  3. When you submit an untitled blog, a red alert is displayed and an error message is given that the title is required
  4. The list of blogs scrolls to the top to display the latest blogs

Test the framework

QUnit is the default test framework for this manual, but Ember .js also supports testing frameworks from other third parties.

How to run the test

Enter the ember test to run the test. You can also re-run the test after each file change with the ember test -server command.

When you develop a project locally, you /tests/index.html by accessing ember server provided that you run your project using the command ember server. If you are using this way there is one thing to note:

  • Tests ember server are tests in a development environment and call parameters in a development environment
  • Tests ember test --server are tests in a test environment that invokes parameters in the test environment, such as loading dependencies. Therefore, we recommend that ebmer test --server to run the test.

Specify the test

Use --filter to specify how to run some tests. F or example: quickly run the current work of the test using the ember test --filter="dashboard" run the specified type ember test --filter="integration" you can ! to exclude acceptance test ember test --filter="!acceptance"