如何在IntelliJ中把一个目录转换为一个包?

问题描述 投票:0回答:1

我正在建立一个Cucumber+Java项目,项目结构如下。

Project structure

我的配置正确地映射了主类,特征文件夹 和glue被映射到 "stepdefs"。

然而,当尝试运行测试时,我会得到Cucumber的 "step undefined "消息。

Step undefined
You can implement missing steps with the snippets below:
@Given("user is on the homepage")
public void user_is_on_the_homepage() {
    // Write code here that turns the phrase above into concrete actions
    throw new io.cucumber.java.PendingException();
}

我注意到这个类的名字 Steps.java 文件被突出显示,并抱怨说 "步骤定义类必须在命名的包中":

Step definition class must be in named package

我试过只加 package stepdefs 到文件的顶部,但这似乎并不奏效("stepdefs "会被下划线,并加上注记 "包名'stepdefs'不符合文件路径''").

更新。

经过@tashkhisi的一些建议,这是我的新项目结构。

enter image description here

java intellij-idea cucumber cucumber-jvm
1个回答
1
投票

enter image description here

下面的第一个链接对于开始使用Cucumber是非常有用的,我建议你按照这个链接来做更好的解释。

开始使用黄瓜

但这里应该是你的目录结构,我建议你使用传统的名称,但如果你决定这样做:标记步骤def为测试源根目录。

更新。

你的主目录必须是test而不是main。

运行测试的@RunWith(Cucumber.class)注释在哪里?

为什么不使用下面的命令来创建最佳的目录结构?

在java和resource里面,你应该有相同的目录结构。

mvn archetype:generate                      \
   "-DarchetypeGroupId=io.cucumber"           \
   "-DarchetypeArtifactId=cucumber-archetype" \
   "-DarchetypeVersion=5.6.0"               \
   "-DgroupId=hellocucumber"                  \
   "-DartifactId=hellocucumber"               \
   "-Dpackage=hellocucumber"                  \
   "-Dversion=1.0.0-SNAPSHOT"                 \
   "-DinteractiveMode=false"

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.