Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

translate ui-test #151

Merged
merged 2 commits into from
Mar 23, 2018
Merged

translate ui-test #151

merged 2 commits into from
Mar 23, 2018

Conversation

yutingzhao1991
Copy link
Contributor

No description provided.

---
order: 15
title: UI Test
type: 进阶
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

漏翻了..

type: 进阶
---

UI testing is an important part of the project development process. Effective test cases can sort out business needs and ensure the quality and progress of development, It make engineers can refactor the code and add new features without trepidation.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it enables developers to refactor the code and add new features safely.


UI testing is an important part of the project development process. Effective test cases can sort out business needs and ensure the quality and progress of development, It make engineers can refactor the code and add new features without trepidation.

Ant Design Pro comes packaged with a handy set of easy-to-use React unit tests and E2E test framework to run test cases by running the following command at the project root.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

easy-to-use 可以删掉

需要断句 -> Ant Design Pro comes packaged with a handy set of React unit tests and E2E test framework, you can run the following command in the root repository to run test cases:


<img src="https://gw.alipayobjects.com/zos/rmsportal/bNkhdMosBxuEhhKgnROo.png" width="700" />

Now we start a quick introduction to writing your business test cases in your project.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now we'll give a brief introduction about how to write a test case.


## Unit Tests

Unit tests are used to test the appearance of React UI components。We referenced [create-react-app](https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#running-tests), using [jest](http://facebook.github.io/jest/) as a test framework.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

中文句号

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By referencing create-react-app, we take jest as the test framework.


Unit tests are used to test the appearance of React UI components。We referenced [create-react-app](https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#running-tests), using [jest](http://facebook.github.io/jest/) as a test framework.

jest is a node-side test framework that uses jsdom to simulate the DOM environment and is suitable for quick testing of the logical behavior of React components. If requiring a real browser, please refer to the E2E test section.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

首字母大写

If you care about the performance in a real browser ...


### Write a case

For example, we could create a file `src/routes/Result/Success.test.js` to test the UI appearance of successful page components.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... to test the UI appearance of Result/Success.js.

});
```

Here [enzyme](http://airbnb.io/enzyme/docs/api/index.html) is used as a test library, which provides a number of useful APIs to help us test React components. Assert part use the jest acquiescence [jasmine2 expect grammar](https://facebook.github.io/jest/docs/en/expect.html#content).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As for the assertion library, we choose jasmine2 expect grammar.


### Local execution

Use the following command will be search and execute `* .test.js` format test case file in `src`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Files with suffix * .test.js in src will be found out and executed by using the following command:

$ npm test .test.js
```

#### Executes a single or a set of cases
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Execute


### Test dva wrapped components

Components wrapped by dva `connect` can use the following way to test.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can use the following way to test the components wrapped by dva connect.

});
```

## e2e test
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

e2e 部分已替换为 Puppeteer,中文文档需要更新,这里先忽略吧

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@valleykid 这部分文档需要更新

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

好的,我近期提个pr修改下文档

$ npm test -- --watch
```

Add `--watch` configuration can enter the watch mode, when you modify and save the file, Jest will automatically execute the corresponding test cases. Jest's command line tools also provide a variety of convenient shortcuts to execute the use cases you need.
Copy link
Contributor

@ddcat1115 ddcat1115 Mar 12, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By adding --watch configuration you can enter the watch mode, in which when you modify and save the file...

Jest -> jest


<img src="https://camo.githubusercontent.com/bd0bbda8e44ea747e4c199d0e212d40563ad2fcb/687474703a2f2f692e696d6775722e636f6d2f356246686e54532e706e67" width="700" />

## Focus or ignore use cases
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use -> test


## Access integration testing services

If you need access to integrated test environment such as travis, CircleCI, Gitlab CI, you can refer to `.travis.yml` provided by this repository.
Copy link
Contributor

@ddcat1115 ddcat1115 Mar 12, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

integrated test -> integration testing

provided by this repository. 给个master的文件链接,中文也加下吧


If you need access to integrated test environment such as travis, CircleCI, Gitlab CI, you can refer to `.travis.yml` provided by this repository.

Note that the e2e test requires integrated environment support, and if not, you can run unit tests separately using `npm test .test.js`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

support electron 并加个链接


## Reference link

For more testing tips and functions, please refer to the following link.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

links


Ant Design Pro comes packaged with a handy set of easy-to-use React unit tests and E2E test framework to run test cases by running the following command at the project root.
Ant Design Pro comes packaged with a handy set of React unit tests and E2E test framework, you can run the following command in the root repository to run test cases by running the following command at the project root.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

by running the following command at the project root. 重复了


End-to-end testing, also known as smoke testing, is used to test the process and appearance of front-end applications in a real-world browser environment, equivalent to operating application instead of manually.

We import [puppeteer](https://github.com/googlechrome/puppeteer) as a tool for E2E testing, 测试的工具,puppeteer is a headless Chrome tool which created by Google, it use chrome / chromium as the browser environment by default to runing your application, and provides a very semantic API for describing business logic.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

测试的工具乱入...

@ddcat1115 ddcat1115 merged commit c591ce1 into master Mar 23, 2018
@afc163 afc163 deleted the yu-tran-ui-test branch March 23, 2018 09:10
@afc163
Copy link
Member

afc163 commented Mar 23, 2018

合并后记得删分支

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants