Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BeforeTestRun resp. AfterTestRun added #2

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions JExample/trunk/src/main/ch/unibe/jexample/AfterTestRun.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package ch.unibe.jexample;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

/**
*
* @author Thilo Ammon
*/
@Retention(RetentionPolicy.RUNTIME)
public @interface AfterTestRun {

}
13 changes: 13 additions & 0 deletions JExample/trunk/src/main/ch/unibe/jexample/BeforeTestRun
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package ch.unibe.jexample;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this file is missing .java extension.


import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

/**
*
* @author amm
*/
@Retention(RetentionPolicy.RUNTIME)
public @interface BeforeTestRun {

}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public Description getDescription() {
return description;
}

public Object getImplementingClass() {
public Class<?> getImplementingClass() {
return jclass;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,22 @@ public Collection<MethodReference> getMethods() {
public void run(ExampleClass testClass, RunNotifier notifier) {
if (!anyHasBeenRun) onStartRunning();
anyHasBeenRun = true;

for(Method m : testClass.getImplementingClass().getMethods()){
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I remember @BeforeClass functions are run lazily in Example#bareInvoke when the first example function of an example class is run. Did you try that?

if (!m.isAnnotationPresent(BeforeTestRun.class)) continue;
Reflection.invoke(m, null);
}

for (Example e: this.getExamples()) {
if (testClass.contains(e)) {
e.run(notifier);
}
}

for(Method m : testClass.getImplementingClass().getMethods()){
Copy link
Owner

@akuhn akuhn Jun 13, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I remember other example classes may depend on cached results from testClass even after these @ AfterTestRun functions have been run, are you okay with this limitation?

Have you considered scanning for @AfterClass annotations here rather than defining a new kind of annotation?

if (!m.isAnnotationPresent(AfterTestRun.class)) continue;
Reflection.invoke(m, null);
}
}

private void onStartRunning() {
Expand Down