Java Selenium 中的 TestNG 和 JUnit 框架是什么
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19325350/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What are TestNG and JUnit frameworks in Selenium
提问by God_Father
I have started learning selenium through YouTube videos and online tutorial..
我已经开始通过 YouTube 视频和在线教程学习硒。
I now have knowledge on Creating Classes, Interfaces, Objects, Inheritance, Arrays, Loops in Java.
我现在掌握了在 Java 中创建类、接口、对象、继承、数组、循环的知识。
As far as Selenium is concerned, I am able automate directly in Selenium using Java language by identifying each elements using Firebug/Firepath tool.
就 Selenium 而言,我可以通过使用 Firebug/Firepath 工具识别每个元素,使用 Java 语言直接在 Selenium 中自动化。
But I constantly hear about TestNG and JUnitframeworks...
但我经常听说TestNG 和 JUnit框架......
- What are these?
- How are they related to selenium?
- Is it difficult to pick them up with the amount of knowledge I currently possess?
- 这些是什么?
- 它们与硒有什么关系?
- 以我目前拥有的知识量很难掌握它们吗?
回答by BlackHatSamurai
JUnit is the basic testing framework that Java uses. It relates to selenium in that if you are doing any testing and you wanted to write the tests with Java, you would use JUnit to write the tests, and hook into Selenium. The answer to your third question is hard to answer. JUnit is java based, so if you know Java, you'll be fine. Assuming that you have a basic understanding of programming, you should be fine.
JUnit 是 Java 使用的基本测试框架。它与 selenium 相关,因为如果您正在做任何测试并且想用 Java 编写测试,您将使用 JUnit 编写测试,并连接到 Selenium。你的第三个问题的答案很难回答。JUnit 是基于 Java 的,所以如果你知道 Java,你会没事的。假设您对编程有基本的了解,应该没问题。
TestNG is similar to JUnit, but it is not the 'defacto' test framework for Java.
TestNG 类似于 JUnit,但它不是 Java 的“事实上的”测试框架。
Here are some links that might help:
以下是一些可能有帮助的链接:
http://testng.org/doc/index.html
回答by Nathan Merrill
They are tools to help you organize your tests. You can define what you want to run before/after tests, you can group your tests, and reporting on them is made easier.
It is usually mentioned with Selenium because Selenium is a common testing tool. The two work together well, but they are completely separate. (Selenium connects you to your browser, TestNG/JUnit organizes the tests)
Yes. You should be able to pick them up. They are designed to be fairly easy to learn.
它们是帮助您组织测试的工具。您可以定义要在测试之前/之后运行的内容,可以对测试进行分组,并且可以更轻松地报告它们。
它通常与 Selenium 一起提及,因为 Selenium 是一种常见的测试工具。两者合作得很好,但它们是完全分开的。(Selenium 将您连接到浏览器,TestNG/JUnit 组织测试)
是的。你应该能把它们捡起来。它们被设计成相当容易学习。
回答by Mayur Shah
JUnit is shipped with most of the IDEs such as Eclipse and NetBeans. There are many testing frameworks being developed using JUnit.
JUnit 随大多数 IDE(例如 Eclipse 和 NetBeans)一起提供。有许多测试框架正在使用 JUnit 开发。
TestNG is an open source framework. It supports parametrization, data driven testing, parallel execution. JUnit is not much flexible for these.
TestNG 是一个开源框架。它支持参数化、数据驱动测试、并行执行。JUnit 对这些不太灵活。
I prefer TestNG over JUnit. I have developed open source testing framework using TestNG for Selenium. You may want to have a look at it.
我更喜欢 TestNG 而不是 JUnit。我已经使用 TestNG for Selenium 开发了开源测试框架。你可能想看看它。
https://github.com/selenium-webdriver-software-testing/kspl-selenium-helper
https://github.com/selenium-webdriver-software-testing/kspl-selenium-helper
回答by Mandar Kale
You can very well create automated script with the amount selenium and Java knowledge you have. But now, if your manager asks you to run all of your testscript and publish report of pass fail to him. Very primitive way to do this, is add name of your test scripts in excel, get its result by running one by one in eclipse IDE or equivalent and update result in excel.
您可以使用您拥有的大量硒和 Java 知识很好地创建自动化脚本。但是现在,如果您的经理要求您运行所有测试脚本并将通过报告发布给他。执行此操作的非常原始的方法是在 excel 中添加测试脚本的名称,通过在 eclipse IDE 或等效程序中一一运行获得其结果并在 excel 中更新结果。
To avoid this, you can use testNG or junit. TestNG and junit are test framework. One part of automation is developing automation script, another is running it. Junit & TestNG helps in running the automated scripts. which includes, preparing test data, manage it, run tests, publish/store execution report, clear/delete testdata.
为避免这种情况,您可以使用 testNG 或 junit。TestNG 和 junit 是测试框架。自动化的一部分是开发自动化脚本,另一部分是运行它。Junit & TestNG 有助于运行自动化脚本。其中包括准备测试数据、管理它、运行测试、发布/存储执行报告、清除/删除测试数据。
You can pick up the TestNG or junit knowledge easily for happy path scenarios. Need to put extra efforts in handling complex situations.
您可以轻松获取 TestNG 或 junit 知识以获取快乐路径场景。需要付出额外的努力来处理复杂的情况。
You will also come across terms like Jenkins or CI (Continuous Integration) along with this. Stay Enthusiastic. Its wonderful world of Automation framework.
您还会遇到诸如 Jenkins 或 CI(持续集成)之类的术语。保持热情。其美妙的自动化框架世界。