Changeset 3887


Ignore:
Timestamp:
04/07/08 11:54:48 (12 years ago)
Author:
curtis
Message:

Add ability to test single files with testng.filename property.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/build.xml

    r3860 r3887  
    372372    classpath="jar/ant-contrib-1.0b1.jar"/> 
    373373 
     374  <!-- 
     375  <taskdef resource="proguard/ant/task.properties" 
     376    classpath="jar/proguard.jar"/> 
     377  --> 
     378 
    374379  <!-- Global build targets --> 
    375380 
     
    491496      suitename="LOCI software test suite"> 
    492497      <classfileset dir="${classes.dir}" includes="${testng.classes}"/> 
     498      <sysproperty key="testng.filename" value="${testng.filename}"/> 
    493499      <sysproperty key="testng.directory" value="${testng.directory}"/> 
    494500      <sysproperty key="testng.multiplier" value="${testng.multiplier}"/> 
  • trunk/loci/tests/testng/FormatReaderTest.java

    r3828 r3887  
    376376  public void testConsistent() { 
    377377    if (!initFile()) return; 
     378    if (config == null) throw new SkipException("No config tree"); 
    378379    String file = reader.getCurrentFile(); 
    379380    String testName = "testConsistent"; 
     
    491492  public void testPerformance() { 
    492493    if (!initFile()) return; 
     494    if (config == null) throw new SkipException("No config tree"); 
    493495    String file = reader.getCurrentFile(); 
    494496    String testName = "testPerformance"; 
     
    604606  public void testPixelsHashes() { 
    605607    if (!initFile()) return; 
     608    if (config == null) throw new SkipException("No config tree"); 
    606609    String file = reader.getCurrentFile(); 
    607610    String testName = "testPixelsHashes"; 
     
    818821 
    819822      // initialize configuration tree 
    820       config.setId(id); 
     823      if (config != null) config.setId(id); 
    821824    } 
    822825    catch (Throwable t) { 
  • trunk/loci/tests/testng/FormatReaderTestFactory.java

    r3784 r3887  
     1// 
     2// FormatReaderTestFactory.java 
     3// 
     4 
     5/* 
     6LOCI software automated test suite for TestNG. Copyright (C) 2007-@year@ 
     7Melissa Linkert and Curtis Rueden. All rights reserved. 
     8 
     9Redistribution and use in source and binary forms, with or without 
     10modification, are permitted provided that the following conditions are met: 
     11  * Redistributions of source code must retain the above copyright 
     12    notice, this list of conditions and the following disclaimer. 
     13  * Redistributions in binary form must reproduce the above copyright 
     14    notice, this list of conditions and the following disclaimer in the 
     15    documentation and/or other materials provided with the distribution. 
     16  * Neither the name of the UW-Madison LOCI nor the names of its 
     17    contributors may be used to endorse or promote products derived from 
     18    this software without specific prior written permission. 
     19 
     20THIS SOFTWARE IS PROVIDED BY THE UW-MADISON LOCI ``AS IS'' AND ANY 
     21EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
     22WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 
     23DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY 
     24DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 
     25(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
     26LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 
     27ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
     28(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 
     29SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
     30*/ 
     31 
    132package loci.tests.testng; 
    233 
     
    738import loci.formats.*; 
    839 
     40/** 
     41 * Factory for scanning a directory structure and generating instances of 
     42 * {@link FormatReaderTest} based on the image files found. 
     43 * 
     44 * <dl><dt><b>Source code:</b></dt> 
     45 * <dd><a href="https://skyking.microscopy.wisc.edu/trac/java/browser/trunk/loci/tests/testng/FormatReaderTestFactory.java">Trac</a>, 
     46 * <a href="https://skyking.microscopy.wisc.edu/svn/java/trunk/loci/tests/testng/FormatReaderTestFactory.java">SVN</a></dd></dl> 
     47 */ 
    948public class FormatReaderTestFactory { 
    1049 
     
    2059   */ 
    2160  public Object[] createInstances() { 
    22     // parse base directory 
    23     final String baseDirProp = "testng.directory"; 
    24     String baseDir = System.getProperty(baseDirProp); 
    25     if (!new File(baseDir).isDirectory()) { 
    26       if (baseDir == null || baseDir.equals("${" + baseDirProp + "}")) { 
    27         LogTools.println("Error: no base directory specified."); 
    28       } 
    29       else LogTools.println("Error: invalid base directory: " + baseDir); 
    30       LogTools.println("Please specify a directory containing files to test:"); 
    31       LogTools.println("   ant -D" + baseDirProp + 
    32         "=\"/path/to/data\" test-all"); 
     61    Vector files = new Vector(); 
     62 
     63    // parse explicit filename, if any 
     64    final String nameProp = "testng.filename"; 
     65    String filename = System.getProperty(nameProp); 
     66    if (filename != null && !new File(filename).exists()) { 
     67      LogTools.println("Error: invalid filename: " + filename); 
    3368      return new Object[0]; 
    3469    } 
    35     FormatReaderTest.config = new ConfigurationTree(baseDir); 
    36  
    37     // create log file 
    38     createLogFile(); 
    39     LogTools.println("testng.directory = " + baseDir); 
     70 
     71    String baseDir = null; 
     72    if (filename == null) { 
     73      // parse base directory 
     74      final String baseDirProp = "testng.directory"; 
     75      baseDir = System.getProperty(baseDirProp); 
     76      if (!new File(baseDir).isDirectory()) { 
     77        if (baseDir == null || baseDir.equals("${" + baseDirProp + "}")) { 
     78          LogTools.println("Error: no base directory specified."); 
     79        } 
     80        else LogTools.println("Error: invalid base directory: " + baseDir); 
     81        LogTools.println( 
     82          "Please specify a directory containing files to test:"); 
     83        LogTools.println("   ant -D" + baseDirProp + 
     84          "=\"/path/to/data\" test-all"); 
     85        return new Object[0]; 
     86      } 
     87      FormatReaderTest.config = new ConfigurationTree(baseDir); 
     88 
     89      // create log file 
     90      createLogFile(); 
     91      LogTools.println("testng.directory = " + baseDir); 
     92    } 
    4093 
    4194    // parse multiplier 
     
    57110    LogTools.println("Maximum heap size = " + maxMemory + " MB"); 
    58111 
    59     // scan for files 
    60     Vector files = new Vector(); 
    61     System.out.println("Scanning for files..."); 
    62     long start = System.currentTimeMillis(); 
    63     getFiles(baseDir, files); 
    64     long end = System.currentTimeMillis(); 
    65     double time = (end - start) / 1000.0; 
    66     LogTools.println(DIVIDER); 
    67     LogTools.println("Total files: " + files.size()); 
    68     LogTools.print("Scan time: " + time + " s"); 
    69     if (files.size() > 0) { 
    70       long avg = (end - start) / files.size(); 
    71       LogTools.println(" (" + avg + " ms/file)"); 
    72     } 
    73     else LogTools.println(); 
    74     LogTools.println(DIVIDER); 
     112    if (filename == null) { 
     113      // scan for files 
     114      System.out.println("Scanning for files..."); 
     115      long start = System.currentTimeMillis(); 
     116      getFiles(baseDir, files); 
     117      long end = System.currentTimeMillis(); 
     118      double time = (end - start) / 1000.0; 
     119      LogTools.println(DIVIDER); 
     120      LogTools.println("Total files: " + files.size()); 
     121      LogTools.print("Scan time: " + time + " s"); 
     122      if (files.size() > 0) { 
     123        long avg = (end - start) / files.size(); 
     124        LogTools.println(" (" + avg + " ms/file)"); 
     125      } 
     126      else LogTools.println(); 
     127      LogTools.println(DIVIDER); 
     128    } 
     129    else { 
     130      files.add(filename); 
     131    } 
    75132 
    76133    // create test class instances 
     
    81138      tests[i] = new FormatReaderTest(id, multiplier); 
    82139    } 
    83     System.out.println("Ready to test " + tests.length + " files"); 
     140    if (tests.length == 1) System.out.println("Ready to test " + files.get(0)); 
     141    else System.out.println("Ready to test " + tests.length + " files"); 
    84142 
    85143    return tests; 
Note: See TracChangeset for help on using the changeset viewer.