In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Most people don't understand the knowledge points of this article "What are the methods for Java to write functional tests for Liberty", so Xiaobian summarizes the following contents for everyone. The contents are detailed, the steps are clear, and they have certain reference value. I hope everyone can gain something after reading this article. Let's take a look at this article "What are the methods for Java to write functional tests for Liberty".
Three ways to use Liberty for functional testing
There are many ways to use IBM WebSphere Liberty and Open Liberty for functional testing. This article covers the 3 approaches I think are best suited for these platforms:
Use build scripts/tools to start and stop Liberty servers
Starting and stopping Liberty servers using JUnit rules
Starting and stopping Liberty servers with Arquillian
Build with Maven
Liberty supports the most common build tools, such as Maven, Gradle, and Ant. You can use any of these tools to run tests on your application, but this article focuses on Maven.
One of the benefits of building applications using a build system like Maven is that you can configure it to run a set of automated tests. The war plug-in extends Java plug-ins to provide testing tasks. You can write tests for individual code units outside of the running application server (unit tests), or you can write them to invoke the application running on the server (integration tests).
Advantages of using common build tools
Some of the benefits of using build tools such as Maven, Ant, or Gradle include:
It keeps Java code simple; no special setup code is required in the JUnit test class.
The artifact you are testing is the user directory containing the configuration and build generated application WAR, so it is closely testing the production artifact.
Deploying artifacts remotely (e.g., in the cloud) and running tests against that deployment is simple without changing the test code.
Disadvantages of using generic build tools
Some of the possible disadvantages of using common build tools include:
There are additional dependencies on Maven plugins (or other build tool plugins).
You can only run tests automatically from the build tool. You cannot do this from Eclipse (or another IDE) without first starting the server manually.
Using JUnit Rules
Using JUnit ClassRule allows you to control your Liberty server from your code using the Liberty System Programming Interface (SPI). From here, you can configure the server and start and stop it.
The following example is an example of how we can programmatically start and stop Liberty servers from our test class:
public class RuleFunctionalTest { @ClassRule public static ExternalResource serverResource = new ServerResource(); public static class ServerResource extends ExternalResource { private final Server server; public ServerResource() { String usrDir = System.getProperty("liberty.usr.dir"); String serverName = System.getProperty("liberty.server.name"); ServerBuilder sb = new ServerBuilder(); server = sb.setName(serverName).setUserDir(new File(usrDir)).build(); } @Override protected void before() throws Throwable { Future startReturnCode = server.start(); Result result = startReturnCode.get(); assertEquals(true, result.successful()); } @Override protected void after() { Future stopReturnCode = server.stop(); try { Result result = stopReturnCode.get(); assertEquals(true, result.successful()); } catch (InterruptedException | ExecutionException e) { e.printStackTrace(); fail("Caught exception stopping server" + e.getMessage()); } } } } Advantages of using JUnit rules
Some of the benefits of using JUnit rules include:
Using JUnit rules keeps building code simple. You simply create a new test task and the standard Maven settings for the source set.
You can run it using the IDE as well as by building.
There are no external dependencies.
Disadvantages of using JUnit rules
Some of the disadvantages of using JUnit rules include:
Using this rule complicates Java code because it is responsible for starting and stopping Liberty servers and running tests.
Deploying to different locations is difficult because this is done through Java APIs.
You need to build a fully functional Liberty user directory structure, including your server configuration and applications. In this example, this fits perfectly in this case because this is already the output of the build, but this is not always the case.
Use of Arquillian
The final technique for functional testing in Libery is to use Arquillian, a testing framework that develops automated functional, integration, and acceptance tests for your Java applications. Arquillian sets up your test environment and handles the application server lifecycle for you so you can focus on writing tests.
Advantages of using Arquillian for functional testing
Some of the benefits of using Arquillian include:
It allows you to create and deploy test archives through tests using ShrinkWrap. There is no need to build a fully functional Liberty server before running tests.
You can use the IDE as well as run Arquillian by building.
Arquillian is the most feature-rich option. For example, you can run tests against multiple containers (application servers) and remote servers.
Pass the correct URL of the application to the test, so you have more flexibility over port numbers and so forth for the test environment.
Disadvantages of using Arquillian for functional testing
Arquillian still needs to define a skeleton server, which must go into the main server runtime installation location (separate user directories are not supported).
The app you are testing was created by Arquillian with the ShrinkWrap tool. You will not deploy this actual application or own this server configuration.
The above is about the content of this article on "Java for Liberty to write functional tests", I believe everyone has a certain understanding, I hope the content shared by Xiaobian is helpful to everyone, if you want to know more relevant knowledge content, please pay attention to the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.