e.g. Calendar Search Help
You must enter a value before pressing Search
ant

Class: org.apache.tools.ant.taskdefs.optional.junit.JUnitTest   ©

 OK to copy?
001 /*
002  * Copyright  2000-2004 The Apache Software Foundation
003  *
004  *  Licensed under the Apache License, Version 2.0 (the "License");
005  *  you may not use this file except in compliance with the License.
006  *  You may obtain a copy of the License at
007  *
008  *      http://www.apache.org/licenses/LICENSE-2.0
009  *
010  *  Unless required by applicable law or agreed to in writing, software
011  *  distributed under the License is distributed on an "AS IS" BASIS,
012  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013  *  See the License for the specific language governing permissions and
014  *  limitations under the License.
015  *
016  */
017 
018 package org.apache.tools.ant.taskdefs.optional.junit;
019 
020 import java.util.Enumeration;
021 import java.util.Hashtable;
022 import java.util.Properties;
023 import java.util.Vector;
024 import org.apache.tools.ant.Project;
025 
026 /**
027  * <p> Run a single JUnit test.
028  *
029  * <p> The JUnit test is actually run by {@link JUnitTestRunner}.
030  * So read the doc comments for that class :)
031  *
032  * @since Ant 1.2
033  *
034  * @see JUnitTask
035  * @see JUnitTestRunner
036  */
037 public class JUnitTest extends BaseTest implements Cloneable {
038 
039     /** the name of the test case */
040     private String name = null;
041 
042     /** the name of the result file */
043     private String outfile = null;
044 
045     // @todo this is duplicating TestResult information. Only the time is not
046     // part of the result. So we'd better derive a new class from TestResult
047     // and deal with it. (SB)
048     private long runs, failures, errors;
049     private long runTime;
050 
051     // Snapshot of the system properties
052     private Properties props = null;
053 
054     public JUnitTest() {
055     }
056 
057     public JUnitTest(String name) {
058         this.name  = name;
059     }
060 
061     public JUnitTest(String name, boolean haltOnError, boolean haltOnFailure,
062                      boolean filtertrace) {
063         this.name  = name;
064         this.haltOnError = haltOnError;
065         this.haltOnFail = haltOnFailure;
066         this.filtertrace = filtertrace;
067     }
068 
069     /**
070      * Set the name of the test class.
071      */
072     public void setName(String value) {
073         name = value;
074     }
075 
076     /**
077      * Set the name of the output file.
078      */
079     public void setOutfile(String value) {
080         outfile = value;
081     }
082 
083     /**
084      * Get the name of the test class.
085      */
086     public String getName() {
087         return name;
088     }
089 
090     /**
091      * Get the name of the output file
092      *
093      * @return the name of the output file.
094      */
095     public String getOutfile() {
096         return outfile;
097     }
098 
099     public void setCounts(long runs, long failures, long errors) {
100         this.runs = runs;
101         this.failures = failures;
102         this.errors = errors;
103     }
104 
105     public void setRunTime(long runTime) {
106         this.runTime = runTime;
107     }
108 
109     public long runCount() {
110         return runs;
111     }
112 
113     public long failureCount() {
114         return failures;
115     }
116 
117     public long errorCount() {
118         return errors;
119     }
120 
121     public long getRunTime() {
122         return runTime;
123     }
124 
125     public Properties getProperties() {
126         return props;
127     }
128 
129     public void setProperties(Hashtable p) {
130         props = new Properties();
131         for (Enumeration e = p.keys(); e.hasMoreElements();) {
132             Object key = e.nextElement();
133             props.put(key, p.get(key));
134         }
135     }
136 
137     public boolean shouldRun(Project p) {
138         if (ifProperty != null && p.getProperty(ifProperty) == null) {
139             return false;
140         } else if (unlessProperty != null
141                     && p.getProperty(unlessProperty) != null) {
142             return false;
143         }
144 
145         return true;
146     }
147 
148     public FormatterElement[] getFormatters() {
149         FormatterElement[] fes = new FormatterElement[formatters.size()];
150         formatters.copyInto(fes);
151         return fes;
152     }
153 
154     /**
155      * Convenient method to add formatters to a vector
156      */
157     void addFormattersTo(Vector v) {
158         final int count = formatters.size();
159         for (int i = 0; i < count; i++) {
160             v.addElement(formatters.elementAt(i));
161         }
162     }
163 
164     /**
165      * @since Ant 1.5
166      */
167     public Object clone() {
168         try {
169             JUnitTest t = (JUnitTest) super.clone();
170             t.props = props == null ? null : (Properties) props.clone();
Rate171             t.formatters = (Vector) formatters.clone();
172             return t;
173         } catch (CloneNotSupportedException e) {
174             // plain impossible
175             return this;
176         }
177     }
178 }

            
All Examples in File:
Example
Line
Rating (found
useful by...)
171 0% of 0