2016-09-09 4 views
0

Я хотел бы сообщить StackTrace моего исключения из консоли, так что если у меня есть:BeforeStories исключение

@BeforeStories 
public void init() { 
    throw new RuntimeException("omg"); 
} 

Я хотел бы иметь:

java.lang.RuntimeException: omg 
    at com.mycompany.MyClass.init(MyClass.java:69) 

Возможно ли это?

ответ

0

Я не уверен, что я понимаю, чего вы пытаетесь достичь, поскольку выброс исключения должен уже регистрировать отказ консоли.

, но если вы хотите просто напечатать сообщение об исключении и tracestack утешать вы можете сделать строку ниже, хотя это довольно страшно должно дать вам то, что вы хотите:

@BeforeStories 
public void runBeforeAllStories() { 
    new RuntimeException("omg").printStackTrace(); 
} 

приложение будет продолжать работать, но будет выход ниже текст в консоли:

java.lang.RuntimeException: OMG в jbehave.sample.steps.LifecycleSteps.runBeforeAllStories (LifecycleSteps.java:31) на sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Метод) на sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62) на sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43) в java.lang.reflect.Method.invoke (Method.java : 498) в org.jbehave.core.steps.StepCreator $ MethodInvoker.invoke (StepCreator.java:805) в org.jbehave.core.steps.StepCreator $ BeforeOrAfterStep.perform (StepCreator.java:491) в org.jbehave.core.embedder.PerformableTree $ FineSoFar.run (PerformableTree.java:340) на org.jbehave.core.embedder.PerformableTree $ PerformableSteps.perform (PerformableTree.java:1072) в org.jbehave.core.embedder.PerformableTree.performBeforeOrAfterStories (PerformableTree.java:427) на org.jbehave.core.embedder.StoryManager.performStories (StoryManager.java:117) на org.jbehave.core.embedder .StoryManager.runStories (StoryManager.java:107) на org.jbehave.core.embedder.StoryManager.runStoriesAsPaths (StoryManager.java:86) на org.jbehave.core.embedder.Embedder.runStoriesAsPaths (Embedder.java : 213) на jbehave.sample.common.StoriesTest.run (StoriesTest.java:161) при sun.reflect.NativeMethodAccessorImpl.invoke0 (нативный метод) при sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62) на sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43) в java.lang.reflect.Method.invoke (Method.java:498) в org.junit.runners.model.FrameworkMethod $ 1.runReflectiveCall (FrameworkMethod.java:47) на org.junit.internal.runners.model.ReflectiveCallable.run (ReflectiveCallable.java:12) на org.junit.runners.model.FrameworkMethod.invokeExplosively (FrameworkMethod.java:44) на org.junit.internal.runners.statements.InvokeMethod.evaluate (InvokeMethod.java:17) в org.junit.runners.ParentRunner.runLeaf (ParentRunner.java:271) в org.junit.runners.BlockJUnit4ClassRunner .runChild (BlockJUnit4ClassRunner.ja va: 70) по адресу org.junit.runners.BlockJUnit4ClassRunner.runChild (BlockJUnit4ClassRunner.java:50) at org.junit.runners.ParentRunner $ 3.run (ParentRunner.java:238) в org.junit.runners.ParentRunner $ 1.schedule (ParentRunner.java:63) на org.junit.runners.ParentRunner.runChildren (ParentRunner.java:236) на org.junit.runners.ParentRunner.access $ 000 (ParentRunner.java:53) на org.junit.runners.ParentRunner $ 2.evaluate (ParentRunner.java:229) в org.junit.runners.ParentRunner.run (ParentRunner.java:309) в org.junit.runner.JUnitCore.run (JUnitCore.java:160) по адресу com.intellij.junit4. JUnit4IdeaTestRunner.startRunnerWithArgs (JUnit4IdeaTestRunner.java:117) по адресу com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithA RGS (JUnit4IdeaTestRunner.java:42) на com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart (JUnitStarter.java:262) на com.intellij.rt.execution.junit.JUnitStarter.main (JUnitStarter. java: 84)

0

Прежде всего, я ценю, что вы хотите показать свое исключение забавным способом. Вы можете выразить свое исключение, просто добавив броски Exception к методу @BeforeStories, как показано ниже.

@BeforeStories 
public void init() throws Exception{ 
    throw new RuntimeException("omg"); 
}