2016-07-13 40 views
4

我正试图在现有的netbeans应用程序上添加一些功能测试。
关于应用程序的信息:由maven包装,使用的netbeans平台7.3.1。 我已在此article如何描述的依赖关系,但有例外:功能测试(Jellytools)不能在netbeans平台上启动

Running qa.FuncTest 
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.067 sec <<< FAILURE! - in qa.FuncTest 
[email protected](org.netbeans.junit.NbModuleSuite$S) Time elapsed: 0.066 sec <<< ERROR! 
java.lang.ClassNotFoundException: org.netbeans.Main 
    at java.net.URLClassLoader$1.run(URLClassLoader.java:202) 
    at java.security.AccessController.doPrivileged(Native Method) 
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190) 
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306) 
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247) 
    at org.netbeans.junit.NbModuleSuite$S.runInRuntimeContainer(NbModuleSuite.java:819) 
    at org.netbeans.junit.NbModuleSuite$S.access$100(NbModuleSuite.java:667) 

有谁知道为什么它的发生?以及如何解决它? 在此先感谢。

UPD依赖从应用/ pom.xml的部分

<dependencies> 
    <dependency> 
     <groupId>org.netbeans.cluster</groupId> 
     <artifactId>platform</artifactId> 
     <version>${software.netbeans.version}</version> 
     <type>pom</type> 
    </dependency> 
    <dependency> 
     <groupId>org.netbeans.api</groupId> 
     <artifactId>org-jdesktop-beansbinding</artifactId> 
     <version>${software.netbeans.version}</version> 
    </dependency> 
    <dependency> 
     <groupId>org.netbeans.api</groupId> 
     <artifactId>org-netbeans-modules-nbjunit</artifactId> 
     <version>${software.netbeans.version}</version> 
     <scope>test</scope> 
    </dependency> 
    <dependency> 
     <groupId>org.netbeans.api</groupId> 
     <artifactId>org-netbeans-modules-jellytools-platform</artifactId> 
     <version>${software.netbeans.version}</version> 
     <scope>test</scope> 
    </dependency> 
</dependencies> 

UPD1测试类:

package qa; 

import junit.framework.Test; 
import org.netbeans.jellytools.JellyTestCase; 
import org.netbeans.jellytools.OptionsOperator; 
import org.netbeans.junit.NbModuleSuite; 
import org.openide.windows.TopComponent; 

public class FuncTest extends JellyTestCase { 

    public static Test suite() { 
     return NbModuleSuite.allModules(FuncTest.class); 
    } 

    public FuncTest(String n) { 
     super(n); 
    } 

    public void testWhatever() throws Exception { 
     TopComponent tc = new TopComponent(); 
     tc.setName("label"); 
     tc.open(); 
     OptionsOperator.invoke().selectMiscellaneous(); 
     Thread.sleep(5000); 
     System.err.println("OK."); 
    } 
} 
+0

请分享在您的pom.xml中使用的依赖关系 – nullpointer

+0

@nullpointer在更新 –

+0

中添加并且您的java类请 – nullpointer

回答

0

我想和大家分享我的调查结果。我注意到,当启动应用程序,如往常一样,我在输出窗口看到:

Installation   =.../application/target/application/extra 
          .../application/target/application/java 
          .../application/target/application/kws 
          .../application/target/application/platform 

但是当应用程序是通过nbjubit/jellytool开始我只看到:

Installation   =.../application/target/application/platform 

,所以我决定扩大这种价值观和调查源代码。让我们考虑NbModuleSuite.java一些有趣的方法:

private static String[] tokenizePath(String path) { 
     List<String> l = new ArrayList<String>(); 
     StringTokenizer tok = new StringTokenizer(path, ":;", true); // NOI18N 


    ..... 
     } 

static File findPlatform() { 
     String clusterPath = System.getProperty("cluster.path.final"); // NOI18N 
     if (clusterPath != null) { 
      for (String piece : tokenizePath(clusterPath)) { 
       File d = new File(piece); 
       if (d.getName().matches("platform\\d*")) { 
        return d; 
       } 
      } 
     } 
     String allClusters = System.getProperty("all.clusters"); // #194794 
     if (allClusters != null) { 
      File d = new File(allClusters, "platform"); // do not bother with old numbered variants 
      if (d.isDirectory()) { 
       return d; 
      } 
     } 


    .... 
     } 

static void findClusters(Collection<File> clusters, List<String> regExps) throws IOException { 
     File plat = findPlatform().getCanonicalFile(); 
     String selectiveClusters = System.getProperty("cluster.path.final"); // NOI18N 
     Set<File> path; 
     if (selectiveClusters != null) { 
      path = new TreeSet<File>(); 
      for (String p : tokenizePath(selectiveClusters)) { 
       File f = new File(p); 
       path.add(f.getCanonicalFile()); 
      } 
     } else { 
      File parent; 
      String allClusters = System.getProperty("all.clusters"); // #194794 
      if (allClusters != null) { 
       parent = new File(allClusters); 
      } else { 
       parent = plat.getParentFile(); 
      } 
      path = new TreeSet<File>(Arrays.asList(parent.listFiles())); 
     } 


.... 
     } 

正如你所看到的,我们可以在cluster.path.finalall.clusters设置路径值,并使用;:作为定界符。我花了一些时间与这个常数玩,认识到设置不成立的pom.xml:

<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-surefire-plugin</artifactId> 
    <version>${software.maven-surefire-plugin}</version> 
    <configuration> 
     <skipTests>false</skipTests> 
     <systemPropertyVariables> 
      <branding.token>${brandingToken}</branding.token> 
      <!--problem part start--> 
      <property> 
       <name>cluster.path.final</name> 
       <value>${project.build.directory}/${brandingToken}/platform:${project.build.directory}/${brandingToken}/java:...etc</value> 
      </property> 
      <!--problem part end--> 
     </systemPropertyVariables> 
    </configuration> 
</plugin> 

但这项工作做得很好:

<properties> 
    <cluster.path.final>${project.build.directory}/${brandingToken}/platform:${project.build.directory}/${brandingToken}/java:...etc</cluster.path.final> 
</properties> 
<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-surefire-plugin</artifactId> 
    <version>${software.maven-surefire-plugin}</version> 
    <configuration> 
     <skipTests>false</skipTests> 
     <systemPropertyVariables> 
      <branding.token>${brandingToken}</branding.token> 
      <cluster.path.final>${cluster.path.final}</cluster.path.final> 
     </systemPropertyVariables> 
    </configuration> 
</plugin> 

我不知道为什么会发生但我会建议使用maven部分properties来设置maven-surefire-plugin的systemPropertyVariables。祝你好运!