1. Trang chủ
  2. » Công Nghệ Thông Tin

WebSphere Studio Application Developer Version 5 Programming Guide part 63 potx

10 142 0
Tài liệu đã được kiểm tra trùng lặp

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 10
Dung lượng 216,75 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

Running a Java test caseIn the Component Test perspective, in the Execution view, right-click Banking Test Case 1 and then select Run from the context menu.. Figure 17-17 Run BankingTest

Trang 1

Running a Java test case

In the Component Test perspective, in the Execution view, right-click Banking Test Case 1 and then select Run from the context menu This is shown in Figure 17-17

Figure 17-17 Run BankingTestCase 1 in the execution view The run test case wizard opens, as shown in Figure 17-18 Here you give a name

to this execution

Figure 17-18 Define the name of the execution Click Next, then you select the host to run the tests on, as shown in Figure 17-19

In our case, we will use the localhost You could, however, execute tests on any server that has the IBM Agent Controller installed New hosts can be defined by clicking New Host

Trang 2

Figure 17-19 Define the host where the test case will be executed Click Next, and you are taken to the final page of the wizard, which allows you to describe the execution After you have done that, click Finish to begin executing the test case

When the execution is running, you will see next to the execution in the execution view After it has completed, the running man disappears

Report test case results

Upon completion of execution, you can generate reports to analyze the test results To do so, select a completed execution and select Report from the context menu (Figure 17-20)

Figure 17-20 Report results of an execution

Trang 3

The new report wizard opens (Figure 17-21) Here you can select the type of report to generate Each report provides different details In our case, we select HTML Report - All (html)

Figure 17-21 Select report to generate Select the Open browser check box and make sure the Open editor check box is not selected If you select both, the new report will open twice

Click Next to proceed to the next page of the wizard, where you select the output location of the report (Figure 17-22) In a larger application, you could organize reports into folders of a project In our case, we will simply generate the report in the root folder of the ItsoProGuideJUnit project

Figure 17-22 Define name and location of the report

Trang 4

We enter BankingTestCaseReport as the report name, and will have the report output to the ItsoProGuideJUnit location Click Finish to complete the wizard and open the new report

Figure 17-23 shows the report in the Web browser The top of the report shows the execution statistics The remainder of the report shows the details of each step of the test execution in the info field, including:

򐂰 Starting the test case

򐂰 Connecting to the local host

򐂰 Verifying that an agent is available to connect to

򐂰 Connecting to the agent

򐂰 Starting the JUnit test cases

򐂰 Completing the JUnit test cases

򐂰 Reporting the results

򐂰 Completing the test

Figure 17-23 Banking test case report

The complete report is available as

BankingTestCaseReport.html , in

\sg24657\sampcode\test-junit

Trang 5

Creating an HTTP test case

HTTP test cases use the HTTP scheduler to perform specific queries and HTTP operations against a server HTTP test cases can consist of the following:

򐂰 HTTP tasks (a request of some sort, with various options)

򐂰 Delays, which instruct the test case to wait a certain amount of time before continuing

򐂰 Blocks, which organize the tasks and verification points into groups that can

be repeated

򐂰 Other HTTP test cases (pulled in by reference) You can create HTTP tasks directly in the Component Test perspective, or you can import a record of HTTP interactions in XML format

We will now create a simple HTTP test case and create our own HTTP task to call a servlet

In the Component Test perspective, select Testcases in the Definition view and select New -> Testcase from the context menu In the new test case window, select ItsoProGuideJUnit as the location and enter HTTPTestCase as the name of the new test case (Figure 17-24)

Figure 17-24 Create new HTTP test case

Note: This section assumes that you have an existing WebSphere Application

Server started and running on port 9080 Note that this is the default port for test servers within Application Developer

Trang 6

Select HTTP in the define attributes of the test case page, and click Finish to complete the wizard (Figure 17-25)

Figure 17-25 Define attributes for new HTTP test case

The new test case has now been created and is open in the editor, as shown in Figure 17-26

Figure 17-26 HTTP test case

In outline view, right-click Main Block and select New -> Task -> HTTP from the context menu A new task has now been created for the test case

Change the name to be FirstHTTPTest and the description to be whatever you want for this task (Figure 17-27)

Trang 7

Figure 17-27 HTTP test case with new HTTP task Select Design in the left column, then in the right part of the editor, specify the following options:

򐂰 Request Method: GET

򐂰 Host Name: localhost

򐂰 Port: 9080

򐂰 Absolute Path: / The result is shown in Figure 17-28

Figure 17-28 Design of HTTP test case

Trang 8

Click Execute request to test the request against the given host, port, and path A server must exist and be running on the specified port, otherwise an error message is shown

You will see a small message below the Execute request button:

Response: 404 - Content Type:html/text - Bytes:142

Change the path to /ItsoProGuideBasicWeb and click Execute request again This time the message is:

Response: 200 - Content Type:html/text - Bytes:1249

The first response (404) is the typical file not found message, the second message indicates success

Change the path back to / and save the test case We want to see a failure Select the HTTPTestCase and Prepare from the context menu in the Definition view This generates the Java code for the test case This wizard is explained in detail in “Preparing a Java test case” on page 591

Running an HTTP test case is done in the same way as running a Java test case, except that the generated Java test case code does not need to be updated For more details about running the test case, see “Running a Java test case” on page 594 The difference here is in the name of the test case

Finally, reporting results from an HTTP test case is the same as a Java test case For more details, see “Report test case results” on page 595 The actual report is slightly different, as shown in Figure 17-29

To have a successful run, open the comptest.http.httptestcase1.MainBlock class and change one line to:

firstHTTPTest.setAbsolutePath("/ItsoProGuideBasicWeb");

Rerun the test case as execution2 and generate the report again

Trang 9

Figure 17-29 HTTP test case report

As you can see, there was a softFail due to a 404 error reported from the HTTP server because no file existed at the root of the server HTTP test cases read the header of the HTTP response to determine whether tests pass or fail In our case, there was no file at the root of the localhost If there had been, then the test would have passed

This concludes our introduction of HTTP test cases This is a new and useful feature of Application Developer that can be used to automate testing and reporting of HTTP requests

The complete report is available as

HTTPTestCaseReport.html , in

\sg24657\sampcode\test-junit

Trang 10

Testing is a valuable part of software development Application Developer includes JUnit and component testing tools that speed up development of test cases, therefore making them more easily accessible

In this chapter, we covered the following topics:

򐂰 What is JUnit?

򐂰 Preparing for JUnit

򐂰 Creating the test case

򐂰 Running the test case

򐂰 Component testing

Ngày đăng: 03/07/2014, 20:20

TỪ KHÓA LIÊN QUAN