Java test mode

xiaoxiao2021-03-06  18

Java test mode

From:

http://www.51testing.com Author: Marco Torchiano Translator: Zhang Hua

Test mode is a high-frequency problem with a high frequency in the software test, which has been practiced and has a valid specialized, efficient solution (method), which plays between the software theory and practices " The role of bridges. In the process of object-oriented Java program test, a more tricky problem is the visibility of the Java class. "Information hidden" is almost a prominent advantage for object-oriented language design, but it also brings a lot of inconvenience to test, and testability of "hidden information" has become a major highcompose of this type of test. To this end, we take the corresponding test mode to support the test of the relevant Java class (package) for the view of the "visual" requirements of the Java class. This paper mainly summarizes five common Java test modes to readers. These five modes are equally fitted with other object-oriented (package) tests, but the difference in concealment of Java language information is considered in specific details. For example: Java's visibility is with the same amount of access to other classes in the same package. C is classified as a class, only the subclass and friends function can access the hidden information of the base class. We will give five commonly described Java test modes in the following way, and the description of the model is the pattern name, test object, for problems, constraints, solutions, instances, constraints, and the test. Design principle. Mode (1) Main mode

Pattern MAIN Test Objects Java class For problem testers don't know where to write drivers and initialization The test code constraint test of the test class must be easy to run, the test code can access all features (all attributes and methods) Solution Put the test code into the class PUBLIC Static Void Main (String [] args) {someclass result; // perform the test ... system.out.print ("Result IS .. ");} The constraint resolves the test code to be first activated and executed, and can access all feature design principles of the test class, the Java class can have a public static void main (String [] args) method, it is class in JVM The method of being taken first, controlling the execution logic of the entire class, and the main method can access all attributes and method modes of the class class (2) TSTRING mode

Pattern TOSTRING Test Object As a class of operation results, the problem tester does not know how to verify the intermediate result of an operation object and the final result constraint test result represents a state inside the object, and the state must be able to be tested by using the TSTRING method To describe the class state, the description result can be compared by printing with the expected results Class SomeClass {// ... public string toString () {// Custom representation}} constraint Solution The internal state of the class is made by the string. Solving the design principle In the base class definition to provide a description of the status of a particular object, determine whether the object state is compliant with the expected mode (3) Equal mode by printing and displaying the object state description.

Mode Name Equal Test Object Java Class For Problem As a Class Constraint Tester for Computing Results Does Not know how to verify an intermediate result of an operational object and the final result Solution Definition Equals method compares the actual results to compare examples Class SomeClass {// ... Public Boolean Equals (Object O) {// Custom Comparison}} The constraint resolves the object that maintains a state needs to compare with the expected object. By comparing the Boolean value to determine if the design principle is defined in the base class with the expected result. Public Boolean Equals (Object) is able to compare the difference between the icon and return comparison results in Boolean value (IV) Internal Tester Class mode Mode Name Internal Tester Class test object Java package For problem testers I don't know where to write test code test packages The class constraint test code and the run code must be separated, the test code can access all the characteristics of the class, and the test code acts as a client of a package. Solution New Category and the package path of this class is the same as the packet path of the test class, then write all the test code instances in this class; public class internaltestclass {// ...} constraint resolve all test code Separation is separated from the running code, since it is under the same packet path, it defines the test code in a specific class compared to the normal client. Since the test class is under the same packet path, it can access all the features of the class of the test class. Therefore, it has greater visibility than client testing. Mode (5) Extern Tester Class mode

Pattern Name EXTERN TESTER CLASS Mode Test Object JAVA Pack For problem testers I don't know where to write the class constraint test code in the test package, the test code must be separated, the test code can access the visual features of the class, the test code starts It is a role of a package client. Solution New Class, specify the packet paths with the test class, and then write all the test code instance package anotherone; public class externalTestClass {// ...} constraints Solve all test code Separation Since it is in different packet paths, it is defined in a specific class with the same design principle as the usual client's visibility. Since the test class is not in the same package path, it cannot access all the properties and methods of the test class. But it has the same visibility as the client. Therefore, it can be tested in place of the client. The relationship between the five modes of the above is shown in Figure -1: Figure -1 Java test mode illustrates the pattern described above helps the tester in the specific Java code test, while the above Java test mode is also It can be implemented with a test framework like JUnit. Note: This article is made according to Marco Torchiano's "Patterns for Java Program Testing".

转载请注明原文地址:https://www.9cbs.com/read-45066.html

New Post(0)