Java: Leveraging Reflection to Build Dynamic Proxies & Unit Tests

Java    |    Expert
  • 8 videos | 54m 38s
  • Includes Assessment
  • Earns a Badge
Rating 3.7 of 11 users Rating 3.7 of 11 users (11)
Reflection in Java is commonly used to create and use dynamic proxies, which allow you to create objects that implement one or more interfaces at runtime. Reflection is also used to build harnesses for unit testing frameworks to invoke set up and tear down methods and run tests. Use this course to get to grips with these use cases. Work with and learn why dynamic proxies are incredibly powerful. Investigate what happens to methods you invoke on an instance of a dynamic proxy class. Then create a unit-testing framework harness similar to the JUnit framework in Java. Use annotations to identify methods and mark tests to run before using reflection to identify them and run them in the correct sequence. When you're finished, you'll have the ability to use reflection to create dynamic proxies and build harnesses for unit test frameworks.

WHAT YOU WILL LEARN

  • Discover the key concepts covered in this course
    Implement a dynamic proxy to create a dynamic object implementing an interface
    Invoke interface methods and object base class methods on proxies
    Pass proxy method invocations to a real object
  • Create annotations for the setup, teardown, and test case for a unit testing framework
    Annotate test case methods for unit testing
    Execute test cases using a custom test harness
    Summarize the key concepts covered in this course

IN THIS COURSE

  • 2m 33s
    In this video, you’ll learn more about your instructor and this course. You’ll learn what the dynamic proxy and invocation handler are. You’ll explore the topic of creating unit tests using reflection. You will create a unit testing harness and three custom annotations in order to decorate methods that contain the test setup, teardown, and the test cases, and then write code that uses reflection to identify test case methods. FREE ACCESS
  • 10m
    In this video, you’ll learn more about working with dynamic proxies. You’ll talk about reflection in the context of dynamic proxies. A dynamic proxy is an object which implements or seems to implement any interface you like. You can invoke any interface method on that object. But actually, under the hood, that object is relaying the call onto some underlying method. FREE ACCESS
  • Locked
    3.  Invoking Interface and Object Functions on Proxies
    7m 3s
    In this video, you’ll watch a demo. It will pick up where you left off at the end of the last demo. Here, you’ll invoke interface and object functions on proxies. You’ll invoke methods from the Repository interface on this proxy object. On line 17, you’ve invoked the create method from the Repository interface. On line 21 you've invoked the read method, and on line 25, the update method. FREE ACCESS
  • Locked
    4.  Constructing Proxies to Pass Method Invocations
    10m 12s
    In this video, you’ll watch a demo. Here, you’ll tweak your code and make your dynamic proxy more meaningful. To do this, you’ll switch to Main.java and begin by importing the List interface. This is java.util.List imported on line 4. Now, you’ll create a Proxy instance that proxies for the List interface. You’ll abandon your dummy Repository interface entirely. You’ll see the changes you've made to your code are minimal. FREE ACCESS
  • Locked
    5.  Creating Annotations for a Unit Testing Framework
    8m 18s
    In this video, you’ll watch a demo. In this demo, you’ll see how a reflection can be used to implement a unit testing framework. The example you’ll work through is similar in detail to the JUnit testing framework in Java. First, you’ll look at the code you’ll be writing and running in the upcoming demo. You’ll be creating a unit testing framework you’ll have one test class for every Java class you test. FREE ACCESS
  • Locked
    6.  Using Annotations to Write Test Cases
    8m 27s
    In this video, you’ll watch a demo. In this demo, you'll pick up where you left off at the end of the last one. There, you set up your test harness for the employee class. You’ll see onscreen that you have Setup, Teardown, and TestCase methods. Each of those methods is marked with the appropriate annotation. Now, you’ll actually build the framework you’ll use to run these TestCases in an automated fashion. FREE ACCESS
  • Locked
    7.  Running Test Cases Using a Custom Test Harness
    5m 58s
    In this video, you’ll watch a demo. Now that you’ve written your test class, created your custom Annotations, and written the code for your reflection-based test harness, all that remains is for you to run your tests. Before you do that, you’ll take one last look at the test class itself. You’ll head back to EmployeeTest.java. You currently have one TestCase and one Teardown method. FREE ACCESS
  • Locked
    8.  Course Summary
    2m 9s
    In this video, you’ll summarize what you’ve learned in this course. You’ve learned a dynamic proxy class implements a list of interfaces specified at runtime such that a method invocation through one of the interfaces on an instance of the class will be encoded and dispatched to another object through a uniform interface. Methods invoked on an instance of a dynamic proxy class are dispatched to a single method in the instances invocation handler. FREE ACCESS

EARN A DIGITAL BADGE WHEN YOU COMPLETE THIS COURSE

Skillsoft is providing you the opportunity to earn a digital badge upon successful completion on some of our courses, which can be shared on any social network or business platform.

Digital badges are yours to keep, forever.

YOU MIGHT ALSO LIKE

Rating 4.3 of 18 users Rating 4.3 of 18 users (18)
Rating 4.1 of 8 users Rating 4.1 of 8 users (8)

PEOPLE WHO VIEWED THIS ALSO VIEWED THESE

Rating 4.5 of 36 users Rating 4.5 of 36 users (36)
Rating 4.0 of 22 users Rating 4.0 of 22 users (22)
Rating 4.3 of 18 users Rating 4.3 of 18 users (18)