【问题标题】:Testng related query [duplicate]Testng相关查询[重复]
【发布时间】:2012-09-28 13:29:30
【问题描述】:

可能重复:
ClassNotFoundException - for testing purposes

是否可以使用另一个模块中存在的 testng 来运行属于某个其他 maven 模块的类。即。如果有模块 A 和 B,在模块 A 内,我想使用 testng.xml 来运行模块 2。请让我知道它是否可能。谢谢

我猜它可能不允许进行测试......

【问题讨论】:

  • 是的,我试过这样做,但它显示 ClassNotFound 异常,我正在通过 maven 运行,所以我在模块 1 的 pom 中添加了模块 2 的依赖项。我不知道还有什么要做的..
  • 是的,马巴是同一个问题。
  • 好的,我找到了另一种方法。我尝试通过 java 代码(而不是通过 pom.xml)运行该 testng,它运行完美,但通过 eclipse。当我通过命令行运行相同的代码时显示以下错误。无法实例化类 module2。我已将包含类 module2 的文件夹添加到类路径中。
  • 欢迎您。您可以编辑您的原始帖子。请在您的帖子中填写您的更新,而不仅仅是在 cmets 中。

标签: java testing maven testng


【解决方案1】:

据我了解您问题的本质,您应该朝 maven surefire 插件的方向进行调查。 这是关于Unit and Integration Tests With Maven and JUnit Categories的注释 从我当前的项目来看,我使用了以下内容:

rms-web pom:

  <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.11</version>
            <dependencies>
                <dependency>
                    <groupId>org.apache.maven.surefire</groupId>
                    <artifactId>surefire-junit47</artifactId>
                    <version>2.12</version>
                </dependency>
            </dependencies>
                            <configuration>
                <!--<includes>-->
                    <!--<include>**/*.class</include>-->
                <!--</includes>-->
                <excludedGroups>com.exadel.rms.selenium.SeleniumTests</excludedGroups>

            </configuration>

        </plugin>


PassTest.java
package com.exadel.rms.selenium;

import org.junit.Test;

import java.io.IOException;

import static org.junit.Assert.assertTrue;

/**
 * Created with IntelliJ IDEA.
 * User: ypolshchykau
 * Date: 8/28/12
 * Time: 8:38 PM
 * To change this template use File | Settings | File Templates.
 */
public class PassTest {


    @Test
    public void pass() throws IOException, InterruptedException {
        assertTrue(true);
    }
}


SeleniumTests.java

package com.exadel.rms.selenium;

/**
 * Created with IntelliJ IDEA.
 * User: ypolshchykau
 * Date: 8/27/12
 * Time: 6:49 PM
 * To change this template use File | Settings | File Templates.
 */
public class SeleniumTests {
}


LoginPageTestSuite.java
package com.exadel.rms.selenium;

import org.junit.Assert;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.openqa.selenium.By;

import java.io.IOException;

@Category(SeleniumTests.class)
public class LoginPageTestSuite extends BaseSeleniumTest {


    @Test
    public void pressLoginButton() throws IOException, InterruptedException {
        doLogout();
        fluentWait(By.cssSelector(propertyKeysLoader("login.loginbutton"))).click();

        Assert.assertTrue(fluentWait(By.cssSelector(propertyKeysLoader("login.validator.invalidautentication"))).getText().trim().equals("Invalid authentication"));
    }
…..........
}

在完成上述所有步骤后,我运行控制台并运行以下 maven 命令:

mvn -Dmaven.buildNumber.docheck=false -Dmaven.buildNumber.doUpdate=false clean test

用于验证您所有标记的类别是否正常工作。

希望这对您有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-14
    • 1970-01-01
    • 1970-01-01
    • 2023-03-21
    • 1970-01-01
    • 2014-09-04
    相关资源
    最近更新 更多