Some more things I found when looking at the codebase.
JBehaveFrameworkError duplicates the behaviour of java.lang.Error
regarding nested Throwables.
It introduces a NullPointerException in the Constructor
JBehaveFrameworkError(Throwable) - line 38 if the
throwable is null (btw. why the printStackTrace in a Constructor?).
What state has the IntelliJ IDEA Plugin? I built it and copied it manually
to my plugins directory. But it froze IDEA at restart after opening the
jbehave project file? It obviously damaged the jbehave.ipr file, so that I
had to set up the project several times (while trying).
Without looking at your junit support, I played around with the stuff a
bit to get the internal IDEA TestRunner running. With two support classes
it was easily possible to run behaviours as Unit Tests :)
Code follows. One thing that was unsuspected: When creating a
BehaviourClass one has to add a bespoken BehaviourVerifier with the same
listener that is already supplied to the BehaviourClass.verifyTo as
internally the NULL_LISTENER is used for creating the BehaviourVerifier:
Snippet:
BehaviourClass behaviourClass=new BehaviourClass(type, new
BehaviourVerifier(behaviourListener));
behaviourClass.verifyTo(behaviourListener);
as there is no setter for the BehaviourVerifier I have to recreate the
BehaviourClass for each run of the run(TestResult) method.
One other thing: I could not use the before- and afterBehaviour methods of
the BehaviourListener interface as Behaviour itself has no notion of an
identifier for the current behaviour. Only the Result contains information
about the currently executed behaviour. Perhaps an additional Result
parameter would be nice to have for an extended version of the
BehaviorListener.
Thank you
Michael
usage:
* either as inner class (strongly coupled to behaviour) or as normal Test
class
public class BehaviourMethodBehaviour extends UsingMiniMock {
public static class BehaviourMethodBehaviourTest extends BehaviourTest
{
public BehaviourMethodBehaviourTest(String name) {
super(name, BehaviourMethodBehaviour.class);
}
}
...snip...
}
code for the JUnit Wrapper:
package org.jbehave.core.behaviour;
import junit.framework.TestCase;
import junit.framework.TestResult;
/**
* Created: (c) michael.hunger?jexp.de at 22.03.2007 23:00:26
*/
public abstract class BehaviourTest extends TestCase {
private final Class type;
public BehaviourTest(String name,Class type) {
super(name);
this.type=type;
}
public int countTestCases() {
return new BehaviourClass(type).countBehaviours();
}
public void run(TestResult testResult) {
final TestResultBehaviourListener behaviourListener = new
TestResultBehaviourListener(testResult);
BehaviourClass behaviourClass=new BehaviourClass(type, new
BehaviourVerifier(behaviourListener));
behaviourClass.verifyTo(behaviourListener);
super.run(testResult);
}
public void testBehaviour() {}
}
package org.jbehave.core.behaviour;
import org.jbehave.core.listener.BehaviourListener;
import org.jbehave.core.result.Result;
import org.jbehave.core.exception.VerificationException;
import junit.framework.TestResult;
import junit.framework.Test;
import junit.framework.AssertionFailedError;
import junit.framework.TestCase;
/**
* Created: (c) michael.hunger?jexp.de at 22.03.2007 22:39:04
*/
public class TestResultBehaviourListener implements BehaviourListener {
private final TestResult testResult;
public TestResultBehaviourListener(TestResult testResult) {
this.testResult = testResult;
}
public void before(Behaviour behaviour) {
}
public void gotResult(Result result) {
Test test=new TestCase(result.name()) {};
testResult.startTest(test);
if (result.status()==Result.SUCCEEDED) {
result.succeeded();
} else {
if (result.cause() instanceof VerificationException) {
testResult.addFailure(test,new
AssertionFailedError(result.cause().toString()));
} else
testResult.addError(test,result.cause());
}
testResult.endTest(test);
}
public void after(Behaviour behaviour) {
}
}
---------------------------------------------------------------------
To unsubscribe from this list please visit:
http://xircles.codehaus.org/manage_email