簡體   English   中英

如何在 Selenium TestNG 環境中初始化 Spring 應用程序上下文文件

[英]How to initialize Spring application context file in Selenium TestNG environment

如何在 Z38008DD81C2F4D1185ECF6E0CE8 中的 Selenium TestNG 環境中初始化 Spring 應用程序上下文文件?

我嘗試了以下代碼,但它使用的是 classpathapplicationcontext,因此每次構建都會刪除應用程序上下文文件。

 public class SpringInitManager {
        private ClassPathXmlApplicationContext ctx;

    public void init() {// "classpath:applicationContext.xml"
        setCtx(new ClassPathXmlApplicationContext("classpath:applicationContext.xml"));
    }
    // 
    public ClassPathXmlApplicationContext getCtx() {
        return ctx;
    }
    // 
    public void setCtx(ClassPathXmlApplicationContext ctx) {
        this.ctx = ctx;
    }
}

它適用於 Eclipse,但不適用於 IntelliJ。

據我了解你的問題,沒有測試代碼片段,你應該改變測試類如下:

@ContextConfiguration("classpath:applicationContext.xml")
public class TestNGSpringTest extends AbstractTestNGSpringContextTests {
   //testNG test methods...
}

Annotation ContextConfiguration configures how to load Spring context for integration tests and AbstractTestNGSpringContextTests class integrates the Spring TestContext Framework with explicit ApplicationContext testing support in a TestNG environment.

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM