You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tika.apache.org by Annie Burgess <an...@gmail.com> on 2014/04/25 00:23:06 UTC
unit tests and classpaths
Hi dev group,
I'm working on a very simple starter unit test for a new parser and am
coming up with some roadblocks. I suspect it may be classpath related, but
have tried many iterations and am coming up short.
My unit test:
--------
package edu.usc.sunset.burgess.tika;
//JDK imports
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import junit.framework.TestCase;
import java.io.InputStream;
//TIKA imports
import org.apache.tika.metadata.Metadata;
import org.apache.tika.metadata.TikaCoreProperties;
import org.apache.tika.parser.ParseContext;
import org.apache.tika.parser.Parser;
import org.apache.tika.sax.BodyContentHandler;
import org.junit.Test;
import org.xml.sax.ContentHandler;
import java.io.IOException;
/*
* Test cases to exercise the {@link EnviHeaderParser}.
*
*/
public class EnviHeaderParserTest extends TestCase
{
public static final String TEST_STRING = "{GEO-TIFF File Imported into
ENVI [Fri May 25 14:06:23 2012]}";
@Test
public void testParser() throws Exception {
Parser parser = new EnviHeaderParser();
ContentHandler handler = new BodyContentHandler();
Metadata metadata = new Metadata();
InputStream stream = EnviHeaderParser.class
.getResourceAsStream("/test-documents/envi_test_header.hdr");
try {
parser.parse(stream, handler, metadata, new ParseContext());
} finally {
stream.close();
}
// Check text
String content = handler.toString();
assertTrue(content.contains(TEST_STRING));
}
}
-----------------------
Files are located as follows:
tika/tika-parsers/src/test/java/org/apache/tika/parser/envi/EnviHeaderParserTest.java
/tika/tika-parsers/src/test/resources/test-documents/envi_test_header.hdr
/tika/anniedev/src/main/java/edu/usc/sunset/burgess/tika/EnviHeaderParser.java
------------------------
To compile and test code I do:
cd /tika/tika/tika-parsers
mvn -Dtest=EnviHeaderParserTest compile
mvn -Dtest=EnviHeaderParserTest test
-------------------------
I get the following output:
Running edu.usc.sunset.burgess.tika.EnviHeaderParserTest
Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.172 sec
<<< FAILURE!
Results :
Failed tests: testParser(edu.usc.sunset.burgess.tika.EnviHeaderParserTest)
Tests run: 1, Failures: 1, Errors: 0, Skipped:0
-------------------------------------------------------------
Please let me know if any additional information would be helpful.
Any insights are appreciated.
Annie
--
------------------------------------------------------------------------------------------
Ann Bryant Burgess, PhD
Postdoctoral Fellow
Computer Science Department
University of Southern California
Viterbi School of Engineering
Los Angeles, CA
Alaska Science Center/USGS
Anchorage, AK
Cell: (585) 738-7549
Office: (907) 786-7059
Fax: (907) 786-7150
E-mail: anniebryant.burgess@gmail.com
Office Address: 4210 University Dr., Anchorage, AK 99508-4626
-------------------------------------------------------------------------------------------
Re: unit tests and classpaths
Posted by Nick Burch <ap...@gagravarr.org>.
On Thu, 24 Apr 2014, Annie Burgess wrote:
> I'm working on a very simple starter unit test for a new parser and am
> coming up with some roadblocks. I suspect it may be classpath related,
> but have tried many iterations and am coming up short.
At first glance, it looks like your unit test is running fine, but one of
the tests in it is failing
> Running edu.usc.sunset.burgess.tika.EnviHeaderParserTest
> Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.172 sec
> <<< FAILURE!
Check under target to see if maven helpfully wrote a text file telling you
the result of the test, that ought to let you know which assert failed
Nick