Git Product home page Git Product logo

jf-hw-reflection's Introduction

Java Fundamentals. Home Assignment. Reflection

The task is to implement a simplistic test execution engine.

Test execution should follow the rules manifested by the annotations provided with the framework:

  1. @Test - indicates that a class is a test class and for a method it indicates that this is a test method to be executed. Alternatively, the test class can implement the TestCase marker interface with no annotations. Examples:
public class FibTest implements TestCase { 
@Test
public class FibTest { 
  1. @Expected - if the test failes with exception, the framework should be able to handle the failure and mark the test as passed.
@Expected(RuntimeException.class)
public void compareIntegers() { 
    assertEquals(4, 5);
}

In the example above, the equality assertion for the numbers 4 and 5 will throw RuntimeException. The test engine should handle the exception: if the method is marked with @Expected annotation and the annotation parameter matches the exception type that was thrown by test method execution, then the test should be considered as successful.

NB! In case if the test method doesn't throw an exception but it is annotated with @Expected, then the test should be considered as FAILED, since we are expecting that the test to fail and it doesn't - so it doesn't meet our exepectations.

NB! If the test throws an exception which is subclass of the declared exception type, then it is a valid situation and the test should be marked as a successful one.

  1. @Inject - injects a proxy into a field for the specified class instance, e.g:
@Inject(Fib.class)
Fibonacci fib;

The proxy should count the invocations of the target methods. Print the total number of invocations in the execution summary.

Tests are executed by TestExecutor class and you will have to implement the missing methods:

  1. getClasses(String packageName) : find all test classes in a given package. Hint: you can obtain an instance of a relevant class loader:
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();

And then apply ClassLoader.getResources(...) method to locate the available class files. Remember that you can load classes dynamically by fully qualified name: Class.forName("org.zeroturnaround.jf.hw.tests.MyTest")

  1. executeTests(Class<?> clazz) : execute the tests for a given class (instance).

Expected behavior:

Package org.zeroturnaround.jf.hw.tests provides some examples of the tests that we would like to run with the test engine.

Here's the expected output from FibTest execution:

SUCCESS: FibTest.find1stFibonacciNumber
SUCCESS: FibTest.find2ndAnd3rdFibonacciNumber
SUCCESS: FibTest.find10thFibonacciNumber
FAILURE: FibTest.find15thFibonacciNumberWithFailure: EXPECTED: 55, ACTUAL: 610
SUMMARY: EXECUTED 4, PASSED 3, FAILED 1, BUSINESS METHODS INVOKED 5

Notes:

EXECUTED 4 - FibTest has 4 methods marked with @Test annotation and 4 of them were executed

PASSED 3 - 3 tests passed successfully

FAILED 1 - 1 test failed (find15thFibonacciNumberWithFailure)

BUSINESS METHODS INVOKED 5 - fib.calculate() was invoked 5 times

jf-hw-reflection's People

Contributors

antonarhipov avatar

Watchers

 avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.