【问题标题】:Is there a way to get JUnit code coverage when running in the browser?在浏览器中运行时有没有办法获得 JUnit 代码覆盖率?
【发布时间】:2015-07-16 14:15:55
【问题描述】:

我们目前正在努力为我们的一个 JS 库获得更好的代码覆盖率。我已经启动并运行了 The Intern,并且可以在浏览器中运行测试。但是,我们的库在其某些函数中创建 DOM 元素,因此我们无法从终端运行 JUnit,因为 Node.js 不允许在测试中构建 DOM。当我们在浏览器中运行 The Intern 时,我们有没有办法在 html 和控制台输出上获得 JUnit 代码覆盖率?

【问题讨论】:

  • 你不应该做 JSUnit 测试而不是 JUnits 吗?
  • 我确定我们应该这样做,但是我们当前的所有报告都是 JUnit,因此我们希望能够将我们的代码覆盖率输出添加到这些报告中。 JSUnit 是怎么做到的,很好奇?
  • 我完全搞不懂为什么在应该使用 JSUnit 测试/覆盖时你会使用用于 java 的 JUnit 来测试/覆盖 JS 库。完全糊涂了,这会告诉我,如果你完全依赖 JUnits 来覆盖其余的 JS 代码,那么你的报告是错误的。
  • 我不同意你的观点。我很好奇,因为我的团队曾询问是否有可能。如果实习生可以做 JSUnits,那还是可以的。我们只需要能够解析运行浏览器测试时得到的结果。我的问题是,最好的方法是什么?

标签: code-coverage intern


【解决方案1】:

我找到了答案。从此链接:https://theintern.github.io/intern/#local-selenium

Using ChromeDriver (Chrome-only)
If you’re just looking to have a local environment for developing functional tests, a stand-alone ChromeDriver installation works great.

1. Download the latest version of ChromeDriver
2. Set tunnel to 'NullTunnel'
3. Run chromedriver --port=4444 --url-base=wd/hub
4. Set your environments capabilities to [ { browserName: 'chrome' } ]
5. Run the test runner

设置好并运行后,就可以运行了

node_modules/intern/bin/intern-runner.js  config=tests/intern reporters=JUnit filename=junit.xml

这将允许测试在 chrome 实例中运行,然后将结果输出到报告中,然后可以上传到某个地方。

【讨论】:

    猜你喜欢
    • 2017-10-20
    • 1970-01-01
    • 1970-01-01
    • 2023-03-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-18
    相关资源
    最近更新 更多