6. HOW CAN WE BUILD REPORTS
PER INDIVIDUAL TESTS ?
- THROUGH A JUNIT LISTENER
Me
TEXTO
7. TEXTO
JUNIT LISTENERS
▸ Receive notifications when a test starts or ends.
▸ It is an agnostic JVM language solution
▸ It is not necessary create a build tool plugin
▸ It is not necessary change our tests
▸ We can use multiple Listeners per application
simultaneously. != for Runners.
10. TEXTO
DEMO
▸ git clone https://github.com/rpau/junit4git.git
▸ gradle check
▸ As it is - Run all the tests
▸ Without changes (again) - Skip all the tests
▸ With changes - Run the affected tests
11. WERE CAN I STORE THE TESTS
TO COMPARE WITH?
- AS A HIDDEN GIT NOTE
Me
TEXTO
12. TEXTO
GIT NOTES BENEFITS
▸ We do not need a server
▸ They are optionally fetched
▸ They are references to commits
▸ Like Gerrit does with SCA tools ;)
export GIT_NOTES_REF=refs/notes/tests
git notes show
13. HOW ARE WE NOTIFIED WHEN
A CLASS IS LOADED?
- USING A INSTRUMENTATION
Me
TEXTO
14. TEXTO
JAVA AGENTS FOR INTRUMENTING CODE
▸ It is the same solution than code coverage tools apply.
▸ Implementing a ClassFileTransformer you can implement:
▸ We get notifications when a class is loaded (once for the
whole test suite).
protected byte[] instrumentClass(String name, byte[]
classfileBuffer)
16. TEXTO
IMPACT REPORT GENERATION WORKFLOW
▸ Listener notifies the agent when a test T starts
▸ The JVM notifies the agent when a new class C is loaded
▸ The agent modifies the class C constructors to get notified
when a new instance is created.
▸ The test creates an object. The agent becomes notified
and stores that C is used in T.
▸ Listener notifies the agent when the test T finishes.
17. HOW DO WE DYNAMICALLY
MODIFY CODE?
- WITH JAVASSIST
Me
TEXTO
18. TEXTO
WE NEED TO DINAMICALLY MODIFY CODE
▸ In class constructors to notify the agent
▸ In test class to add the @Ignore when it is necessary.
▸ and.. these modifications should:
▸ Not be persistent
▸ Be JVM Language agnostic