【问题标题】:TestNG instead of JUNIT in DukeScriptsDukeScripts 中的 TestNG 而不是 JUNIT
【发布时间】:2017-12-03 09:51:35
【问题描述】:

在 Netbeans(DukeScript 应用程序)的示例示例中,原型为 Maven 创建了这个 POM.xml。我尝试注释掉 JUNIT 依赖项并放入 TestNG。

<dependency>
    <groupId>org.testng</groupId>
    <artifactId>testng</artifactId>
    <version>6.11</version>
    <scope>test</scope>
</dependency>

我仍然遇到错误。 关于如何转换为 Testng 的任何想法? 是的,它们通常只是测试套件,但我有一堆为我想重用的基类构建的代码。

  <?xml version="1.0"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <parent>
      <groupId>b</groupId>
      <artifactId>a-pom</artifactId>
      <version>1.0-SNAPSHOT</version>
  </parent>

  <groupId>b</groupId>
  <artifactId>a</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>bundle</packaging>

  <name>a General Client Code</name>

  <properties>
    <netbeans.compile.on.save>all</netbeans.compile.on.save>
    <project.mainclass>b.a.Main</project.mainclass>
    <exec.java.bin>${java.home}/bin/java</exec.java.bin>
    <exec.debug.arg>-Ddebug=false</exec.debug.arg>
  </properties>
  <build>
      <plugins>
          <plugin>
              <groupId>org.apache.felix</groupId>
              <artifactId>maven-bundle-plugin</artifactId>
              <version>2.4.0</version>
              <extensions>true</extensions>
              <configuration>
                  <instructions>
                      <Export-Package>b.a</Export-Package>
                      <Bundle-SymbolicName>b.a</Bundle-SymbolicName>
                  </instructions>
              </configuration>
          </plugin>
          <plugin>
              <groupId>org.apache.maven.plugins</groupId>
              <artifactId>maven-compiler-plugin</artifactId>
              <version>2.3.2</version>
              <configuration>
                  <source>1.7</source>
                  <target>1.7</target>
              </configuration>
          </plugin>
          <plugin>
              <groupId>org.apache.maven.plugins</groupId>
              <artifactId>maven-surefire-plugin</artifactId>
              <version>2.19.1</version>
              <configuration>
                  <junitArtifactName>com.dukescript.api:junit-osgi</junitArtifactName>
                  <systemPropertyVariables>
                      <fxpresenter.headless>true</fxpresenter.headless>
                  </systemPropertyVariables>
              </configuration>
          </plugin>
          <plugin>
              <artifactId>maven-source-plugin</artifactId>
              <version>2.2.1</version>
              <executions>
                  <execution>
                      <id>attach-sources</id>
                      <phase>post-integration-test</phase>
                      <goals>
                          <goal>jar-no-fork</goal>
                      </goals>
                  </execution>
              </executions>
          </plugin>
          <plugin>
              <groupId>org.codehaus.mojo</groupId>
              <artifactId>exec-maven-plugin</artifactId>
              <version>1.2.1</version>
                <configuration>
                   <executable>${exec.java.bin}</executable>
                   <classpathScope>runtime</classpathScope>
                   <arguments>
                       <argument>-classpath</argument>
                       <classpath/>
                       <argument>-javaagent:${project.build.directory}/springloaded.jar</argument>
                       <argument>-Xverify:none</argument>
                       <argument>-Dbrowser.rootdir=${basedir}/src/main/webapp/</argument>
                       <argument>-Dnetbeans.inspect.port=${netbeans.inspect.port}</argument>
                       <argument>${exec.debug.arg}</argument>
                       <argument>${project.mainclass}</argument>
                   </arguments>
                </configuration>
          </plugin>
          <plugin>
              <groupId>org.apache.maven.plugins</groupId>
              <artifactId>maven-dependency-plugin</artifactId>
              <version>2.10</version>
              <executions>
                  <execution>
                      <id>copy</id>
                      <phase>process-classes</phase>
                      <goals>
                          <goal>copy</goal>
                      </goals>
                      <configuration>
                          <artifactItems>
                              <artifactItem>
                                  <groupId>org.springframework</groupId>
                                  <artifactId>springloaded</artifactId>
                                  <version>1.2.3.RELEASE</version>
                                  <type>jar</type>
                                  <overWrite>false</overWrite>
                                  <destFileName>springloaded.jar</destFileName>
                              </artifactItem>
                          </artifactItems>
                          <outputDirectory>${project.build.directory}</outputDirectory>
                      </configuration>
                  </execution>
              </executions>
          </plugin>
          <plugin>
              <artifactId>maven-assembly-plugin</artifactId>
              <version>2.4</version>
              <executions>
                  <execution>
                      <id>web-pages</id>
                      <phase>package</phase>
                      <goals>
                          <goal>single</goal>
                      </goals>
                      <configuration>
                          <descriptors>
                              <descriptor>src/main/assembly/webpages.xml</descriptor>
                          </descriptors>
                      </configuration>
                  </execution>
              </executions>
          </plugin>
      </plugins>
  </build>
  <dependencies>
    <dependency>
        <groupId>org.netbeans.html</groupId>
        <artifactId>net.java.html</artifactId>
        <version>${net.java.html.version}</version>
    </dependency>
    <dependency>
        <groupId>org.netbeans.html</groupId>
        <artifactId>net.java.html.json</artifactId>
        <version>${net.java.html.version}</version>
    </dependency>
    <dependency>
        <groupId>org.netbeans.html</groupId>
        <artifactId>net.java.html.boot</artifactId>
        <version>${net.java.html.version}</version>
    </dependency>
    <dependency>
        <groupId>org.netbeans.html</groupId>
        <artifactId>net.java.html.sound</artifactId>
        <version>${net.java.html.version}</version>
    </dependency>
    <dependency>
        <groupId>org.netbeans.html</groupId>
        <artifactId>ko4j</artifactId>
        <version>${net.java.html.version}</version>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>b</groupId>
        <artifactId>a-js</artifactId>
        <version>${project.version}</version>
    </dependency>
    <dependency>
        <groupId>org.netbeans.html</groupId>
        <artifactId>net.java.html.boot.fx</artifactId>
        <version>${net.java.html.version}</version>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>com.dukescript.api</groupId>
        <artifactId>junit-osgi</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>com.dukescript.api</groupId>
        <artifactId>junit-browser-runner</artifactId>
        <version>${junit.browser.version}</version>
        <scope>test</scope>
        <type>jar</type>
    </dependency>

    <!-- Nashorn presenter for BrowserRunner
    <dependency>
      <groupId>org.netbeans.html</groupId>
      <artifactId>net.java.html.boot.script</artifactId>
      <version>${net.java.html.version}</version>
      <scope>test</scope>
      <type>jar</type>
    </dependency>
    -->

    <!-- Bck2Brwsr VM presenter for BrowserRunner - - >
    <dependency>
      <groupId>org.apidesign.bck2brwsr</groupId>
      <artifactId>launcher.http</artifactId>
      <version>${bck2brwsr.version}</version>
      <scope>test</scope>
      <type>jar</type>
    </dependency>
    <dependency>
      <groupId>org.apidesign.bck2brwsr</groupId>
      <artifactId>ko-bck2brwsr</artifactId>
      <version>${bck2brwsr.version}</version>
      <classifier>bck2brwsr</classifier>
      <scope>test</scope>
      <type>jar</type>
    </dependency>
    <dependency>
        <groupId>com.dukescript.api</groupId>
        <artifactId>junit-browser-runner</artifactId>
        <version>${junit.browser.version}</version>
        <scope>test</scope>
        <classifier>bck2brwsr</classifier>
        <type>jar</type>
    </dependency>
    < ! - - End of Bck2Brwsr VM presenter for BrowserRunner -->
  </dependencies>
  <profiles>
      <profile>
          <id>javafx</id>
          <activation>
              <activeByDefault>true</activeByDefault>
          </activation>
          <dependencies>
              <dependency>
                  <groupId>org.netbeans.html</groupId>
                  <artifactId>net.java.html.boot.fx</artifactId>
                  <version>${net.java.html.version}</version>
                  <scope>runtime</scope>
              </dependency>
          </dependencies>
      </profile>
      <profile>
          <id>desktop</id>
          <dependencies>
              <dependency>
                  <groupId>org.netbeans.html</groupId>
                  <artifactId>net.java.html.boot.fx</artifactId>
                  <version>${net.java.html.version}</version>
                  <scope>runtime</scope>
              </dependency>
          </dependencies>
          <build>
              <plugins>
                  <plugin>
                      <groupId>org.apache.maven.plugins</groupId>
                      <artifactId>maven-jar-plugin</artifactId>
                      <version>2.4</version>
                      <configuration>
                          <archive>
                              <manifest>
                                  <mainClass>${project.mainclass}</mainClass>
                                  <addClasspath>true</addClasspath>
                                  <classpathPrefix>lib/</classpathPrefix>
                                  <useUniqueVersions>false</useUniqueVersions>
                              </manifest>
                          </archive>
                      </configuration>
                  </plugin>
                  <plugin>
                      <artifactId>maven-assembly-plugin</artifactId>
                      <version>2.4</version>
                      <executions>
                          <execution>
                              <id>distro-assembly</id>
                              <phase>package</phase>
                              <goals>
                                  <goal>single</goal>
                              </goals>
                              <configuration>
                                  <descriptors>
                                      <descriptor>src/main/assembly/javafx.xml</descriptor>
                                  </descriptors>
                              </configuration>
                          </execution>
                      </executions>
                  </plugin>
              </plugins>
          </build>
      </profile>
      <profile>
          <id>webkit-presenter</id>
          <dependencies>
              <dependency>
                  <groupId>com.dukescript.presenters</groupId>
                  <artifactId>webkit</artifactId>
                  <version>${presenters.version}</version>
                  <scope>runtime</scope>
              </dependency>
          </dependencies>
      </profile>
      <profile>
          <id>browser-presenter</id>
          <dependencies>
              <dependency>
                  <groupId>com.dukescript.presenters</groupId>
                  <artifactId>browser</artifactId>
                  <version>${presenters.version}</version>
                  <scope>runtime</scope>
              </dependency>
          </dependencies>
      </profile>
  </profiles>
</project>

【问题讨论】:

    标签: java maven netbeans junit testng


    【解决方案1】:

    在 pom 中添加 testng 依赖 注释掉 2 个 JUNIT 依赖项

    你只需要导入 org.testng。断言;注释。*; 在您的测试包中。

    删除@RunWith

    Assert.assertTrue(arr.get(0).startsWith("Hello"));

    电话留言

    【讨论】:

      猜你喜欢
      • 2013-10-19
      • 2016-11-11
      • 2014-07-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-22
      • 2010-09-05
      • 2013-08-07
      相关资源
      最近更新 更多