角度测试-将玩笑与量角器配合使用 [英] Angular Testing - Using Jest with Protractor

查看:111
本文介绍了角度测试-将玩笑与量角器配合使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Angular测试的新手,我想为我的应用程序执行2种测试:

I am new to Angular testing, and I want to perform 2 kinds of test for my application:

  1. 单元测试-我选择使用 Jest ,因为我可以在不打开浏览器的情况下运行测试,并且还支持使用-testNamePatern 对特定情况进行测试./li>
  2. 端到端测试-我想试用量角器,因为它可以在Angular中使用,并且有很大的Angular社区可以使用.
  1. Unit Test - I choose to use Jest since I can run my test without opening the browser, and it also supports testing for specific cases with --testNamePatern.
  2. End to end test - I want to try out Protractor since it is available in Angular and also has a big Angular community to work with.

我的问题是,我可以在应用程序中同时使用Jest和Protractor吗?如果是,我是否需要配置任何内容以在我的应用程序中使用它们.

My question is, can I use both Jest and Protractor in my application? If yes, do I need to configure anything to use both of them in my application.

推荐答案

您可以在应用程序中同时使用玩笑和量角器.默认情况下,新的角度cli版本为您提供了在同一应用程序中进行单元测试的因果报应运行器和用于端到端测试的量角器运行器.您只是通过Jest改变业力.

You can use both jest and protractor in your application. By default the new angular cli release gives you a karma runner for unit tests and a protractor runner for end to end tests inside the same application. You are just changing Karma with Jest.

1)我可以开玩笑地进行量角器测试(端到端)吗? 不,你不能.

1) Can I run protractor tests (end to end) with jest? No you cannot.

2)我可以使用量角器运行单元测试吗? 你不能.

2) Can I run unit tests using protractor? No you cannot.

3)我可以在同一应用程序中运行量角器进行端到端测试而开玩笑地进行单元测试吗? 是的你可以.您只需要告诉玩笑说要拾取哪些文件,并与量角器相同.

3) Can I run protractor for end to end tests and jest for unit tests in the same application? Yes you can. You will just need to tell jest which files to pick up and the same with protractor.

4)我可以在一个文件中或一次运行中获得两个报告吗? 你不能.您将必须配置笑话运行器以打印与量角器报告不同的报告.

4) Can I get both the reports in a single file or a single run? No you cannot. You will have to configure your jest runner to print reports which will be different from the protractor reports.

您可以同时使用玩笑和量角器,而无需进行任何特殊配置.这是package.json的一个片段,我正在用它运行带有量角器的e2e测试和带有玩笑的灯塔测试.

You can use both jest and protractor without configuring anything special. Here is a snippet of the package.json I am using for running e2e tests with protractor and lighthouse tests with jest.

{
  "name": "performance-tests",
  "version": "1.0.0",
  "description": "Performance tests and end to end tests.",
  "main": "jest.js",
  "scripts": {
    "debug": "node --inspect-brk ./node_modules/.bin/protractor protractor.conf.js",
    "pretest": "npm run tsc && npm run webdriver-update",
    "test": "./node_modules/protractor/bin/protractor protractor/compiled-js-files/protractor.conf.js",
    "e2e": "npm run tsc && ./node_modules/protractor/bin/protractor protractor/compiled-js-files/protractor.conf.js",
    "grid": "sh run-grid.sh && npm run tsc && npm run e2e",
    "tsc": "./node_modules/typescript/bin/tsc",
    "webdriver-update": "./node_modules/protractor/bin/webdriver-manager update --standalone --versions.standalone=3.8.0 --chrome --versions.chrome=78.0.3904.97",
    "lighthouse": "./node_modules/jest/bin/jest.js --verbose -t=lighthouse",
    "lighthouse-reports": "./node_modules/jest/bin/jest.js --verbose -t=lighthouse && node ./lighthouse/db.js"
  },
  "repository": {
    "type": "",
    "url": ""
  },
  "author": "Sankalan Parajuli",
  "license": "ISC",
  "bugs": {
    "url": ""
  },
  "homepage": "",
  "dependencies": {
    "@types/jasmine": "^3.3.12",
    "@types/jasminewd2": "^2.0.6",
    "@types/node": "^12.12.14",
    "jasmine": "^3.3.1",
    "lighthouse": "^4.0.0-beta",
    "protractor": "5.4.2",
    "protractor-beautiful-reporter": "^1.3.3"
  },
  "devDependencies": {
    "@types/request": "^2.48.3",
    "@types/selenium-webdriver": "^4.0.0",
    "csvtojson": "^2.0.8",
    "jest": "^23.4.1",
    "moment": "^2.24.0",
    "mongodb": "^3.1.13",
    "puppeteer": "^1.6.0",
    "request-promise": "^4.2.5",
    "ts-node": "^8.5.2",
    "typescript": "2.8.1"
  }
}

希望它会有所帮助.

这篇关于角度测试-将玩笑与量角器配合使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆