我的测试注释不起作用,eclipse 要求主要方法

My Test annotation not working, eclipse is asking for main method

我尝试使用@Test 编写 selenium 代码,但 eclipse 不是 运行 它并要求使用 Main 方法。 我添加了 Maven 项目并将 Selenium 和 TestNG 依赖项添加到 pom.xml 请帮助解决我面临的问题 示例代码:

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.Test;

public class BaseTest {
    @Test
    public void openBrowser() {
        File file = new File("./src/test/resources/config.properties");
      
    FileInputStream fileInput = null;
    try {
        fileInput = new FileInputStream(file);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
        System.out.println("File not found");
    }
    Properties prop = new Properties();
    
    //load properties file
    try {
        prop.load(fileInput);
    } catch (IOException e) {
        e.printStackTrace();
        System.out.println("Values not found");
    }
    System.setProperty("webdriver.chrome.driver","./src/test/resources/drivers/chromedriver.exe");
    WebDriver driver = new ChromeDriver();
    driver.get(prop.getProperty("baseURL"));
}

}

在运行上面,我面对着

Error: Main method not found in class com.digivalsolutions.digiassess.LoginTest, please define the main method as:
   public static void main(String[] args)
or a JavaFX application class must extend javafx.application.Application

我的 pom.xml 文件:

 <dependencies>
<dependency>
  <groupId>junit</groupId>
  <artifactId>junit</artifactId>
  <version>3.8.1</version>
  <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-java</artifactId>
    <version>3.141.59</version>
</dependency>
<dependency>
    <groupId>org.testng</groupId>
    <artifactId>testng</artifactId>
    <version>7.3.0</version>
    <scope>test</scope>
</dependency>

我认为您应该为 IDE 安装 TestNG。您可以查看此 link 了解更多详情。