如何在 IntelliJ 中将目录转换为包

How do I convert a directory to a package in IntelliJ

我正在使用以下项目结构设置 Cucumber + Java 项目:

我的配置正确映射了主要 class、功能文件夹和胶水映射到 "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 文件中的 class 名称被突出显示并抱怨 "Step definition class must be in named package":

我尝试将 package stepdefs 添加到文件的顶部,但这似乎不起作用("stepdefs" 将带有下划线并附注 "Package name 'stepdefs' does not correspond to the file path ''").

更新:

根据@tashkhisi 的一些建议,这里是我的新项目结构:

首先关注link对于开始使用黄瓜非常有用我建议您关注link以获得更好的解释。

Getting started with Cucumber

但这应该是你的目录结构 我建议您使用常规名称,但如果您决心这样做,请执行以下操作: 将 stepsdef 标记为测试源根目录

更新:

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

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

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

内部java和资源你应该有相同的目录结构

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"