Selenium 4 Java testing framework of best

For decades, Java has been developing applications on the server side programming language of choice. Although JUnit has been together with developers to help them automate unit testing, but over time the development and testing industry, especially with the rise of automated testing, has developed a number of open-source Java-based framework, verifying them and business logic aspects JUnit is different. Here, I will discuss the use of a top-level Java testing framework Selenium WebDriver execute test automation, we will focus on the advantages and disadvantages of these unique and top Java testing framework.

JUnit

Junit is based on xUnit developer developed on the basis of a practical case. The main purpose is to make its initial Java developers to write scripts and execute repeatable test cases. It is often used to test a piece of code. You can also be used by the JUnit test automation and integration of Selenium to perform automated testing site. Whenever you add any new version of the code required when issued, you will need to rerun the entire test cases, and ensure that no does not affect the original function.

What are the prerequisites have?

The framework is highly compatible with Selenium WebDriver for Java, therefore, JUnit and Selenium WebDriver is completely compatible, as are certain prerequisites, you need to

  • Use a newer version of JDK in the work of the project.
  • Download the latest version of JUnit and set the environment.
  • Have a good experience with object-oriented programming language (Java) application development.

The advantages and disadvantages of using JUnit?

JUnit has several advantages:

  • Developers working in an environment driven by the test found it very good, because they are forced to read the code and look for the existence of BUG.
  • As soon as an error is detected, thus greatly improving the reliability of the code.
  • Develop more readable and error-free code can enhance credibility.
  • Using the latest version of JUnit (version 5), you can easily identify abnormalities, it can also be performed using legacy JUnit test cases written.
  • You can also use it with Java 5 and later.

The only drawback is that JUnit:

  • The framework can not perform dependency test. That is where we need the TestNG.

JUnit is your best Java testing framework do?

JUnit and TestNG perform the same work. Their functions are almost the same, only two frames, JUnit can not rely on testing, implementation and different parametric test. In addition, due to the long-term use JUnit, and therefore have a better community support, it has been defined as the standard unit tests for the application of the use of Selenium WebDriver for Java. Although TestNG users is small, but the community is still large, and growing every day. Therefore, we can conclude that, for the Java testing framework, to choose between TestNG or JUnit depends entirely on the nature and requirements of the application.

JBehave

We all know Behavior Driven Development (BDD). This type of test in a manner transparent to the user of the service acceptance test is described. JBehave is another Java BDD testing framework for testing, primarily for use with Selenium WebDriver for Java. The main purpose is to make use JBehave novice can easily understand and are familiar with BDD. This is a design philosophy that allows the testing phase of the application based more on their behavior.

What are the prerequisites have?

The ideal method is used JBehave integrated with IDE. To this end, in addition to the necessary operational environment to build the configuration, you will also need a few jar files, for example,

Junit-4.1.0.jar,Jbehave-core-3.8.jar,Commons-lang-2.4.jar,Paranamer-2.5.jar,Freemarker-2.3.9.jar,Org.apacje.commons.io.jar,Org.apache.commons.collections.jar,Plexus-utils-1.1.jar

JBehave advantages and disadvantages

Like all other BDD testing frameworks, JBehave also has advantages in many aspects.

  • Better coordination between different development teams similar to the specification of different projects, you can achieve the most important objective behavior-driven development.
  • Due to similar specifications, so the project manager and stakeholders can better understand the output of the development team and quality inspection team.
  • Since JBehave with detailed logical reasoning and thinking functions, so the product has better reliability.
  • JBehave semi-official languages, and also has function helps to maintain a consistent team structure behavior.

Like any other BDD testing tools, JBehave only one drawback.

  • Success depends primarily on BDD testing tool of communication between the different members of the project, stakeholders, developers, testers, and organizational management. Lack of communication may not lead to timely detection and rapid resolution of the problem, which may lead to cause application errors or inconsistent with the actual business requirements, leading to all parties accusing each other (thrown pot).

JBehave is best for your Java testing framework do?

JBehave work the same way as Serenity. However, if you intend to improve the efficiency of automatic acceptance testing, it is best to Serenity and JBehave integrated together to take advantage of better testing experience. This is because the core concepts of Serenity BDD-based development, and also allows users to write powerful and rich test report.

Selenide

Selenide-based Selenium testing framework, Selenium by providing technical support, is a popular tool for precise and intuitive UI more test cases. Modern Web technologies (such as Ajax) test has a certain complexity, such as time-out, and wait for the assertion, and so on. WebDriver is a popular tool for UI testing, but the lack of processing time-out function. Selenide a simple way to deal with all these issues. In addition, it is easier to grasp and learn. Just have to do is to focus on business logic, just perform a few simple lines of code to complete your work.

What Selenide prerequisite?

Selenide installation is very simple. If you are using Maven, you need to pom.xmladd the following line in the file.

<dependency>
    <groupId>com.codeborne</groupId>
    <artifactId>selenide</artifactId>
    <version>5.1.0</version>
    <scope>test</scope>
</dependency>复制代码

Selenide advantages and disadvantages

In the front-end tier server side using Java-based applications, the most common problems faced by test is timed out. You write test cases may now be working, but after a few days, maybe a few Ajax request to spend more time than they are now, or some Javascript to run will be slower. In addition, your system may run another process, resulting in a test case fails. Even more unfortunately, you may need to spend a few days to find out the root of these problems. Selenide can help you

  • Simple test case writing process eliminates time-out problems.
  • Supports application development testing AngularJS
  • Most call the function to reduce the use of traditional tools Selenium.

So far, we have not found use Selenide obvious shortcomings, is probably the only reluctantly called the grammar symbols shortcomings.

Place a Demo everyone would understand:

@Test
public void userCanLoginByUsername() {
    open("/login");
    $(By.name("user.name")).setValue("johny");
    $("#submit").click();
    $(".loading_progress").should(disappear); // Waits until element disappears
    $("#username").shouldHave(text("Hello, Johny!")); // Waits until element gets text
}复制代码

It was found that the online Demo not up and running, in fact, is the lack of the necessary initialization steps, as follows:

        Configuration.browser = "Chrome";
        Configuration.baseUrl="https://www.baidu.com";复制代码

Selenide is most suitable for your Java testing framework do?

For UI testing, in addition to Selenide parent frame Selenium WebDriver, there is no better Java-based framework. Obviously, WebDriver can not be resolved by a timeout Ajax, JavaScript running slow or have any questions takes time to load due to dynamic content. To overcome the problem, we previously used in the test case wait_untilor sleepmethods. Use Selenide, we no longer need to consider those issues. Only focus on business logic, test cases can serve its purpose well.

Spock

Spock is derived from a JUnit test automation framework written in Groovy, allowing you to perform DDT (data-driven testing) on ​​the JVM (Java Virtual Machine). It provides compatibility with all languages ​​supported by the JVM. UI Spock offered are very good compared with any other Java testing framework. Code readability and document concise, and can be explained by simple sentences, making it very convenient Java testing framework.

Spock's advantages as Java testing framework

Spock advantages:

  • Excellent readability, provide compatibility with common English sentences.
  • Spock analog and stub been easier than ever. Moreover, both of which are built-in.
  • Parametric shorter and clearer.
  • It provided the surrounding environment, making it easier to find the cause of the malfunction.
  • Expressive and simple DSL (domain specific language).

Spock's shortcomings:

  • You need to have a basic understanding of Groovy.
  • If you are unfamiliar with Spock, you might feel a bit inconvenient to the frame, but once proficient in it, they will not use other Java testing framework.
  • For other Java-based high-level syntax compatibility testing framework is poor (for example Mockito)

Spock is most suitable for your Java testing framework do?

Spock has so many advantages, I believe that Spock would be the best Java testing framework BDD (Behavior Driven Development), because it is simple to use, intuitive UI and powerful DSL. If it happens that your project is a JVM-based application that he is definitely your best choice.

The following is written before the three spock article, Click for details

to sum up

In the current era of agile, developers also need to participate in the test. You need not everyone is an expert, but should have at least basic knowledge of automatic validation test case writing code. This article describes several tools that provides the preferred developer for application UI testing, unit testing and BDD testing. If you really want to work outstanding, and hopes to become more professional developers and testers, the tool will be the daily work mentioned above absolute help.

Technology Featured articles

Non-technical Selected Articles

Guess you like

Origin juejin.im/post/5df05b1f6fb9a0163d1a5b5d