Think in Java notes _chapter20_2_annocation and JUnit

Source: Internet
Author: User
/April 05, 2015 12:13:43 A study of junit based on annotation and reflection:
Package Cn.seven.shengsiyuan.annocation.junitan;import Org.junit.test;public class Junitsource {//The question is why the main method is not written here, Method can be executed directly without being called?? -Reflection @testpublic void Hello () {System.out.println ("Hello World");}}

  1. First, get the class object corresponding to the classes you want to test.
  2. It then obtains the public decorated method array of the object by reflection
  3. Iterate over the array to get each method object
  4. Two methods for judging whether the method object is annotated
    1. Method object. isannotationpresent (annotation class. Class)
    2. The annotation class annotation class object =method object. getannocation (annotation class. Class).
  5. The method is then executed through Method.invoke.

Think in Java notes _chapter20_2_annocation and JUnit

Related Article

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.