Java Test Tips

Source: Internet
Author: User
Tags reflection

Shortcut keys

Modify shortcut key window-"preference-" general-"Keys:
Find references: ctrl+shift+g
Overlay test: Alt+shift+e,t
Copy one line: Ctrl+alt+down
Debug Run: Alt+shift+d,t
Switch
Find references: ctrl+g
Overlay test: Ctrl+w
Copy one line: Ctrl+d
Debug Run: Ctrl+q

Concept

Mutation (number, return value, ErrMsg)
Cyclic use case (Binarysearchtree test2)
Where mutation is prone (custom exception)
Multiple test Cases
With reflection (copy contrast, Datalog Hascode)
My test steps (most code, private functions)
Using the Eclipse Code template
Semi-automated testing: Generate random data, record random data to run branches, record corresponding results to assert

Bug Detection Rate

For a particular scenario, write the test case, run the test case, discover the program's behavior and the expected inconsistency in the test case, and say that the program is a bug.

Behavior inconsistencies are: Return values, operators, conditional judgments, numeric values (references, numbers, string changes), and so on. These are easy to see when the project is upgraded or perfected, and the test cases come in handy to detect if a bug has occurred after the upgrade.

How to detect the validity of test cases? The main indicators are branch (statement) coverage and bug detection rates. The above can be seen, bugs appear in the project upgrade or improvement, change the changes, but in the actual application can not wait until the project upgrade to detect whether the use case is effective, there are tools to simulate these changes, these changes are called "mutation", the program input, after the mutation, the output of multiple copies of code. Each code is considered a bug, because part of the code is changed by the tool, which is inconsistent with the original project code. Using these variants of the code to run test cases, the test case is required to run a failure, so that the detection of a bug, otherwise all passed, then did not detect a bug.

Plug - ins

Coverage plug-in: Eclemma
Mutation Plugin: Http://muclipse.sourceforge.net/site/site.xml
Https://sourceforge.net/projects/muclipse/?source=typ_redirect

Reflection Example
 Packagerefexample;ImportJava.lang.reflect.Field;ImportJava.lang.reflect.Method; Public classMain { Public Static voidMain (string[] args)throwsexception{Class clazz= A.class; {    //calling a parameter static methodMethod f1 = Clazz.getdeclaredmethod ("F2",Newclass[]{int.class}); F1.setaccessible (true); F1.invoke (NULL, 123); }        {  //calling the parameterless static methodMethod f1 = Clazz.getdeclaredmethod ("F2",NULL); F1.setaccessible (true); F1.invoke (NULL,NULL); }        { //Set static PropertiesField field = Clazz.getdeclaredfield ("AA"); Field.setaccessible (true); Field.set (NULL, 7); Method F1= Clazz.getdeclaredmethod ("F1",NULL); F1.setaccessible (true); F1.invoke (NULL,NULL); }        { //Set member PropertiesA A =(A) clazz.newinstance (); Field field= Clazz.getdeclaredfield ("a"); Field.setaccessible (true); Field.set (A,99); Method F1= Clazz.getdeclaredmethod ("F3",NULL); F1.setaccessible (true); F1.invoke (A,NULL); }    }    }classa{Private Static intAA; Private Static voidF1 () {System.out.println (AA); }    Private Static voidF2 (inta)    {System.out.println (a); }    Private Static voidF2 () {System.out.println ("No P 2"); }        Private intA; Private voidF3 () {System.out.println (a); }}

Java Test Tips

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.