To unit test a rule using JUnit

Source: Internet
Author: User

Introduction

An example

Let's take a look at an example to learn the characteristics of unit testing for "rules." We have a performance tuning tool, WPA, that evaluates the values of performance-related parameters and recommends optimal values. Its evaluation and recommended optimal value algorithms are based on "rules".

The initial heap size of the Java virtual machine (JVM initial heap size) is a key parameter that affects the performance of the JVM. Performance Tuning Tool WPA has a set of rules for evaluating the value of JVM initial heap size (see Listing 1). The results of the assessment are 5 levels. The level "1" is well set to improve performance, and the level "5" indicates a poor setting, which can degrade performance.

Listing 1. JVM initial heap Size rating algorithm

Rating3upperbounds = 1024
Rating3lowerbounds = 48
Rating5upperbounds = 1536
Rating5lowerbounds = 32
Rating3multiplier = 4
Rating5multiplier = 3
Absolutemaximumvalue= math.min (currentmemorypoolsize, overallmemoryonpartition)
/Rating3multiplier
if (Initialheapsize > Absolutemaximumvalue) {
return 4;
}
if ((Initialheapsize < rating5lowerbounds) | |
(Initialheapsize > Rating5upperbounds)) {
Rating = Severe problem (5)
}
else if (Initialheapsize < rating3lowerbounds) | |
(Initialheapsize > Rating3upperbounds)) {
Rating = probable problem (3)
}
......
}
if (initialheapsize * rating5multiplier > Currentmemorypoolsize)
{
Return severe problem (5)
}
else if (Initialheapsize*rating3multiplier > Currentmemorypoolsize)
{
Return Max (rating, 3)
}
else if (Initialheapsize*rating2multiplier > Currentmemorypoolsize)
else {
Return Max (rating, 1)
}

In this set of rules, there are three input parameters: "Initialheapsize" (the value of the JVM initial heap size), "Currentmemorypoolsize" (the value of the memory pool), and the Overallmemoryonpartition "(Value of physical memory). To get these values, we need to use the APIs provided by the application Server and OS. When using these APIs, we must construct the runtime environment required by the API.

In this set of rules, there are many different conditions (see "if-else" statements). At the time of testing (unit and functional testing), we need at least 24 sets of test data to cover all thresholds (threshold value) and equivalence classes (equivalent Class). See table 1.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.