JUnit无法识别测试(在Eclipse或Maven中)

时间:2014-02-19 20:19:13

标签: maven junit jbehave jbehave-plugin

我有一个跑步者类作为一些JBehave测试工作的一部分,无论出于什么原因,Eclipse都不会允许JUnit用于“Run As ...”。我尝试通过“mvn -Dtest = LoginTrial test”通过Maven手动启动它,它也没有认出测试。这是它的代码,任何想法将不胜感激。

package tests.acceptanceTests.featureTests.login;

import java.text.SimpleDateFormat;
import java.util.List;

import org.jbehave.core.InjectableEmbedder;
import org.jbehave.core.annotations.Configure;
import org.jbehave.core.annotations.UsingEmbedder;
import org.jbehave.core.annotations.UsingSteps;
import org.jbehave.core.embedder.Embedder;
import org.jbehave.core.embedder.StoryControls;
import org.jbehave.core.io.CodeLocations;
import org.jbehave.core.io.LoadFromClasspath;
import org.jbehave.core.io.StoryFinder;
import org.jbehave.core.junit.AnnotatedEmbedderRunner;
import org.jbehave.core.parsers.RegexPrefixCapturingPatternParser;
import org.jbehave.core.reporters.StoryReporterBuilder;
import org.jbehave.core.steps.ParameterConverters.DateConverter;
import org.junit.Test;
import org.junit.runner.RunWith;

import steps.login.LoginSteps;
import tests.acceptanceTests.featureTests.login.LoginTrial.MyDateConverter;
import tests.acceptanceTests.featureTests.login.LoginTrial.MyReportBuilder;
import tests.acceptanceTests.featureTests.login.LoginTrial.MyStoryControls;
import tests.acceptanceTests.featureTests.login.LoginTrial.MyStoryLoader;


@RunWith(AnnotatedEmbedderRunner.class)
@Configure(storyControls = MyStoryControls.class, storyLoader = MyStoryLoader.class, storyReporterBuilder = MyReportBuilder.class, parameterConverters = { MyDateConverter.class })
@UsingEmbedder(embedder = Embedder.class, generateViewAfterStories = true, ignoreFailureInStories = true, ignoreFailureInView = true, verboseFailures = true,
    storyTimeoutInSecs = 100, threads = 2, metaFilters = "-skip")
@UsingSteps(instances = { LoginSteps.class })
public abstract class LoginTrial extends InjectableEmbedder
{
@Test
public void run() 
{
    List<String> storyPaths = new StoryFinder().findPaths(CodeLocations.codeLocationFromClass(this.getClass()), 
            "../../../../../stories/login_trial.story", "");
    injectedEmbedder().runStoriesAsPaths(storyPaths);
}

public static class MyStoryControls extends StoryControls {
    public MyStoryControls() {
        doDryRun(false);
        doSkipScenariosAfterFailure(false);
    }
}

public static class MyStoryLoader extends LoadFromClasspath {
    public MyStoryLoader() {
        super(LoginTrial.class.getClassLoader());
    }
}

public static class MyReportBuilder extends StoryReporterBuilder {
    public MyReportBuilder() {
        this.withFormats(org.jbehave.core.reporters.Format.HTML, org.jbehave.core.reporters.Format.TXT, org.jbehave.core.reporters.Format.XML).withDefaultFormats();
    }
}

public static class MyRegexPrefixCapturingPatternParser extends RegexPrefixCapturingPatternParser {
    public MyRegexPrefixCapturingPatternParser() {
        super("%");
    }
}

public static class MyDateConverter extends DateConverter {
    public MyDateConverter() {
        super(new SimpleDateFormat("yyyy-MM-dd"));
    }
}   
}

1 个答案:

答案 0 :(得分:2)

您的测试类是抽象的。删除抽象修饰符。