java - 无法解析符号 'Before' - Intellij jUnit

标签 java intellij-idea junit

我是 Intellij IDEA 的新手。我正在尝试使用 jUnit 注释 @Before 和 @After 进行我的 Selenium 测试。即使我在类中导入 jUnit,我也无法使用注释。有什么帮助吗?

package Config;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;
import org.junit.Before;
import org.junit.Test;

public class browserConfig {

    public static WebDriver driver = null;
    public static Properties config = new Properties();
    public static FileInputStream fis;

    @Before
    public void initBrowser(){

        if (driver ==null){

            try{

                fis = new FileInputStream(System.getProperty("user.dir") + "//src//main//java//Config//config.properties");

            } catch (FileNotFoundException e) {

                e.printStackTrace();

            }

最佳答案

你的测试应该在test文件夹中,否则idea会忽略测试注释。 确保该类放置在 src/test/文件夹中。 另请检查项目设置 -> 模块,您的测试文件夹是否存在于结构中并且具有绿色(标记为测试)。如果缺少 - 将其添加到模块中并标记为测试。

关于java - 无法解析符号 'Before' - Intellij jUnit,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50910345/

相关文章:

java - 用于从数据库读取属性的 apache 公共(public)配置的替代方案

java - 第二个参数类型错误,找到 'androidx.lifecycle.Lifecycle',需要 'int' 错误

java - 如何针对 "pull --rebase"冲突重新启动 merge

java - 编辑 java .form xml

java - org.mockito.exceptions.misusing.MissingMethodInitationException

java - 使用 Hibernate 添加数据库后进行单元测试

java - 是否可以使用key和partition来消费kafka消息?

android - 使用适用于 Android 的 Intellij IDEA 新 libgdx 项目运行时出现 NullPointerException

intellij-idea - 文件图标中的问号在 Intellij 中意味着什么?

java - 我如何模拟方法,从另一种方法调用一种方法?