SourceForge.net Logo

JUnit

PDFBox

Orientation in Objects

writing tests

First create a Java project. Than use the JPdfUnit Test Case wizard to create a new testcase class:

  1. Open the New wizard (File > New > JPdfUnit Test Case). If you cannot find the entry, reset the java perspective (Window > Reset perspective) or select (File > New > Other... > Java > JUnit > JPdfUnit TestCase)
  2. A dialog will open asking to add the junit, jpdfunit and pdfbox libraries to the class path. Select Yes.
  3. Enter the name of your test class.
  4. Select setUp() and tearDown() to create this method stubs.
  5. Select a Pdf-Document.
  6. JPdfUnit TestCase creation wizard page 1

  7. Click Finish to create the test class.

A new JUnit TestCase class and a new DocumentTester field will be created. If you select Inherit from DocumentTestCase a new DocumentTestCase class will be created and none DocumentTester field.

package de.oio.test;

import junit.framework.TestCase;
import de.oio.jpdfunit.DocumentTester;

public class OIOTestCase extends TestCase {

	DocumentTester tester;

	protected void setUp() throws Exception {
		super.setUp();
		tester = new DocumentTester("Document.pdf");
	}

	protected void tearDown() throws Exception {
		super.tearDown();
		tester.close();
	}
}
	

If you select Inherit from DocumentTestCase a new DocumentTestCase class will be created and none DocumentTester field.

package de.oio.test;

import de.oio.jpdfunit.DocumentTestCase;
import de.oio.jpdfunit.document.util.DocumentDataSource;
import de.oio.jpdfunit.document.util.PdfDataSource;

public class OIOTest extends DocumentTestCase {

	public OIOTest(String arg0) {
		super(arg0);
	}

	protected DocumentDataSource getDataSource() {
		DocumentDataSource datasource = new PdfDataSource("Document.pdf");
		return datasource;
	}

}
	

Now you are ready to run your first test.

Valid XHTML 1.0! Valid CSS! Desidned by CSS!