It says it contains deprecated errors so I run it with -Xlint:deprecation. I fixed the 3 errors.
Change getControlParser() to newControlParser()
Change new File("...").toURL().toExternalForm() to new File("...").getPath();
Change getTestParser() to newTestParser()
This stops the deprecation warnings and creates the MyXMLTestCase class file.
But when I run it
$ java -cp ".:lib/junit.jar" MyXMLTestCase
Exception in thread "main" java.lang.NoClassDefFoundError: MyXMLTestCase (wrong name: org/custommonkey/xmlunit/examples/MyXMLTestCase)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
How can it be the wrong name when the class has the same name as the file MyXMLTestCase. The class file is being created. I used the correct library. Not sure what I'm doing wrong...
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Tried compiling XMLUnit from source. Downloaded the src.zip file and ran ant in the unzipped directory.
$ ant
Buildfile: /home/user/Downloads/xmlunit/xmlunit-1.5/build.xml
-props:
-init: [mkdir] Created dir: /home/user/Downloads/xmlunit/xmlunit-1.5/build/lib [mkdir] Created dir: /home/user/Downloads/xmlunit/xmlunit-1.5/build/classes [mkdir] Created dir: /home/user/Downloads/xmlunit/xmlunit-1.5/build/test-classes [mkdir] Created dir: /home/user/Downloads/xmlunit/xmlunit-1.5/build/test-report [mkdir] Created dir: /home/user/Downloads/xmlunit/xmlunit-1.5/build/dist [mkdir] Created dir: /home/user/Downloads/xmlunit/xmlunit-1.5/build/doc [mkdir] Created dir: /home/user/Downloads/xmlunit/xmlunit-1.5/build/doc/userguide
compile: [javac] /home/user/Downloads/xmlunit/xmlunit-1.5/build.xml:108: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds [javac] Compiling 54 source files to /home/user/Downloads/xmlunit/xmlunit-1.5/build/classes [javac] warning: [options] bootstrap class path not set in conjunction with -source 1.3 [javac] Note: /home/user/Downloads/xmlunit/xmlunit-1.5/src/java/org/custommonkey/xmlunit/Transform.java uses or overrides a deprecated API. [javac] Note: Recompile with -Xlint:deprecation for details. [javac] 1 warning [javac] /home/user/Downloads/xmlunit/xmlunit-1.5/build.xml:118: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds [javac] Compiling 44 source files to /home/user/Downloads/xmlunit/xmlunit-1.5/build/test-classes [javac] warning: [options] bootstrap class path not set in conjunction with -source 1.3 [javac] Note: Some input files use or override a deprecated API. [javac] Note: Recompile with -Xlint:deprecation for details. [javac] 1 warning
To your first question: java expects the full classname including the package name - but even then that's not how you run JUnit tests (see other thread). Please make yourself familiar with JUnit as XMLUnit 1.x expects you to know JUnit already.
Your second post says you face test failures when you try to run XMLUnit's tests. There may be several reasons for this - including bugs in XMLUnit - but nothing that should prevent you from running tests of your own.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
When I run
javac -cp "lib/junit.jar" MyXMLTestCase.java
It says it contains deprecated errors so I run it with -Xlint:deprecation. I fixed the 3 errors.
Change getControlParser() to newControlParser()
Change new File("...").toURL().toExternalForm() to new File("...").getPath();
Change getTestParser() to newTestParser()
This stops the deprecation warnings and creates the MyXMLTestCase class file.
But when I run it
$ java -cp ".:lib/junit.jar" MyXMLTestCase
Exception in thread "main" java.lang.NoClassDefFoundError: MyXMLTestCase (wrong name: org/custommonkey/xmlunit/examples/MyXMLTestCase)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
How can it be the wrong name when the class has the same name as the file MyXMLTestCase. The class file is being created. I used the correct library. Not sure what I'm doing wrong...
Tried compiling XMLUnit from source. Downloaded the src.zip file and ran ant in the unzipped directory.
$ ant
Buildfile: /home/user/Downloads/xmlunit/xmlunit-1.5/build.xml
-props:
-init:
[mkdir] Created dir: /home/user/Downloads/xmlunit/xmlunit-1.5/build/lib
[mkdir] Created dir: /home/user/Downloads/xmlunit/xmlunit-1.5/build/classes
[mkdir] Created dir: /home/user/Downloads/xmlunit/xmlunit-1.5/build/test-classes
[mkdir] Created dir: /home/user/Downloads/xmlunit/xmlunit-1.5/build/test-report
[mkdir] Created dir: /home/user/Downloads/xmlunit/xmlunit-1.5/build/dist
[mkdir] Created dir: /home/user/Downloads/xmlunit/xmlunit-1.5/build/doc
[mkdir] Created dir: /home/user/Downloads/xmlunit/xmlunit-1.5/build/doc/userguide
compile:
[javac] /home/user/Downloads/xmlunit/xmlunit-1.5/build.xml:108: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds
[javac] Compiling 54 source files to /home/user/Downloads/xmlunit/xmlunit-1.5/build/classes
[javac] warning: [options] bootstrap class path not set in conjunction with -source 1.3
[javac] Note: /home/user/Downloads/xmlunit/xmlunit-1.5/src/java/org/custommonkey/xmlunit/Transform.java uses or overrides a deprecated API.
[javac] Note: Recompile with -Xlint:deprecation for details.
[javac] 1 warning
[javac] /home/user/Downloads/xmlunit/xmlunit-1.5/build.xml:118: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds
[javac] Compiling 44 source files to /home/user/Downloads/xmlunit/xmlunit-1.5/build/test-classes
[javac] warning: [options] bootstrap class path not set in conjunction with -source 1.3
[javac] Note: Some input files use or override a deprecated API.
[javac] Note: Recompile with -Xlint:deprecation for details.
[javac] 1 warning
test:
[junit] Running org.custommonkey.xmlunit.examples.test_CaseInsensitiveDifferenceListener
[junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.172 sec
[junit] Running org.custommonkey.xmlunit.examples.test_CountingNodeTester
[junit] Tests run: 2, Failures: 0, Errors: 0, Time elapsed: 0.014 sec
[junit] Running org.custommonkey.xmlunit.examples.test_FloatingPointTolerantDifferenceListener
[junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.016 sec
[junit] Running org.custommonkey.xmlunit.examples.test_MultiLevelElementNameAndTextQualifier
[junit] Tests run: 5, Failures: 0, Errors: 0, Time elapsed: 0.041 sec
[junit] Running org.custommonkey.xmlunit.examples.test_RecursiveElementNameAndTextQualifier
[junit] Tests run: 8, Failures: 0, Errors: 2, Time elapsed: 0.036 sec
[junit] TEST org.custommonkey.xmlunit.examples.test_RecursiveElementNameAndTextQualifier FAILED
[junit] Running org.custommonkey.xmlunit.examples.test_TextDifferenceListenerBase
[junit] Tests run: 3, Failures: 0, Errors: 0, Time elapsed: 0.015 sec
[junit] Running org.custommonkey.xmlunit.examples.test_XPathRegexAssert
[junit] Tests run: 2, Failures: 0, Errors: 2, Time elapsed: 0.024 sec
[junit] TEST org.custommonkey.xmlunit.examples.test_XPathRegexAssert FAILED
[junit] Running org.custommonkey.xmlunit.jaxp13.test_Jaxp13XpathEngine
[junit] Tests run: 10, Failures: 0, Errors: 0, Time elapsed: 0.075 sec
[junit] Running org.custommonkey.xmlunit.jaxp13.test_Validator
[junit] Tests run: 10, Failures: 0, Errors: 0, Time elapsed: 0.217 sec
[junit] Running org.custommonkey.xmlunit.jaxp13.test_XMLUnitNamespaceContext2Jaxp13
[junit] Tests run: 4, Failures: 0, Errors: 0, Time elapsed: 0.005 sec
[junit] Running org.custommonkey.xmlunit.test_AbstractNodeTester
[junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.011 sec
[junit] Running org.custommonkey.xmlunit.test_BugFixes
[junit] Tests run: 8, Failures: 0, Errors: 0, Time elapsed: 1.173 sec
[junit] Running org.custommonkey.xmlunit.test_Constants
[junit] Tests run: 0, Failures: 0, Errors: 0, Time elapsed: 0.003 sec
[junit] Running org.custommonkey.xmlunit.test_DetailedDiff
[junit] Tests run: 64, Failures: 0, Errors: 1, Time elapsed: 1.153 sec
[junit] TEST org.custommonkey.xmlunit.test_DetailedDiff FAILED
[junit] Running org.custommonkey.xmlunit.test_Diff
[junit] Tests run: 53, Failures: 0, Errors: 1, Time elapsed: 0.21 sec
[junit] TEST org.custommonkey.xmlunit.test_Diff FAILED
[junit] Running org.custommonkey.xmlunit.test_Difference
[junit] Tests run: 4, Failures: 0, Errors: 3, Time elapsed: 0.003 sec
[junit] TEST org.custommonkey.xmlunit.test_Difference FAILED
[junit] Running org.custommonkey.xmlunit.test_DifferenceEngine
[junit] Tests run: 43, Failures: 0, Errors: 16, Time elapsed: 0.034 sec
[junit] TEST org.custommonkey.xmlunit.test_DifferenceEngine FAILED
[junit] Running org.custommonkey.xmlunit.test_DoctypeInputStream
[junit] Tests run: 10, Failures: 0, Errors: 1, Time elapsed: 0.007 sec
[junit] TEST org.custommonkey.xmlunit.test_DoctypeInputStream FAILED
[junit] Running org.custommonkey.xmlunit.test_DoctypeReader
[junit] Tests run: 14, Failures: 0, Errors: 1, Time elapsed: 0.006 sec
[junit] TEST org.custommonkey.xmlunit.test_DoctypeReader FAILED
[junit] Running org.custommonkey.xmlunit.test_ElementNameAndAttributeQualifier
[junit] Tests run: 5, Failures: 0, Errors: 0, Time elapsed: 0.009 sec
[junit] Running org.custommonkey.xmlunit.test_ElementNameAndTextQualifier
[junit] Tests run: 2, Failures: 0, Errors: 0, Time elapsed: 0.003 sec
[junit] Running org.custommonkey.xmlunit.test_ElementNameQualifier
[junit] Tests run: 2, Failures: 0, Errors: 0, Time elapsed: 0.003 sec
[junit] Running org.custommonkey.xmlunit.test_ForumMessage4406472
[junit] Tests run: 2, Failures: 0, Errors: 0, Time elapsed: 0.005 sec
[junit] Running org.custommonkey.xmlunit.test_HTMLDocumentBuilder
[junit] Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0 sec
[junit] TEST org.custommonkey.xmlunit.test_HTMLDocumentBuilder FAILED
[junit] Running org.custommonkey.xmlunit.test_IgnoreTextAndAttributeValuesDifferenceListener
[junit] Tests run: 3, Failures: 0, Errors: 0, Time elapsed: 0.006 sec
[junit] Running org.custommonkey.xmlunit.test_JAXP_1_2_Schema_Validation
[junit] Tests run: 7, Failures: 0, Errors: 0, Time elapsed: 0.024 sec
[junit] Running org.custommonkey.xmlunit.test_NodeDescriptor
[junit] Tests run: 8, Failures: 0, Errors: 0, Time elapsed: 0.011 sec
[junit] Running org.custommonkey.xmlunit.test_NodeInputStream
[junit] Tests run: 2, Failures: 0, Errors: 0, Time elapsed: 0.008 sec
[junit] Running org.custommonkey.xmlunit.test_NodeTest
[junit] Tests run: 2, Failures: 0, Errors: 0, Time elapsed: 0.004 sec
[junit] Running org.custommonkey.xmlunit.test_Replacement
[junit] Tests run: 6, Failures: 0, Errors: 0, Time elapsed: 0.023 sec
[junit] Running org.custommonkey.xmlunit.test_SimpleNamespaceContext
[junit] Tests run: 3, Failures: 0, Errors: 0, Time elapsed: 0.001 sec
[junit] Running org.custommonkey.xmlunit.test_SimpleSerializer
[junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.003 sec
[junit] Running org.custommonkey.xmlunit.test_SimpleXpathEngine
[junit] Tests run: 11, Failures: 0, Errors: 1, Time elapsed: 0.066 sec
[junit] TEST org.custommonkey.xmlunit.test_SimpleXpathEngine FAILED
[junit] Running org.custommonkey.xmlunit.test_TolerantSaxDocumentBuilder
[junit] Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0 sec
[junit] TEST org.custommonkey.xmlunit.test_TolerantSaxDocumentBuilder FAILED
[junit] Running org.custommonkey.xmlunit.test_Transform
[junit] Tests run: 8, Failures: 0, Errors: 0, Time elapsed: 0.032 sec
[junit] Running org.custommonkey.xmlunit.test_Validator
[junit] Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0 sec
[junit] TEST org.custommonkey.xmlunit.test_Validator FAILED
[junit] Running org.custommonkey.xmlunit.test_XMLTestCase
[junit] Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0 sec
[junit] TEST org.custommonkey.xmlunit.test_XMLTestCase FAILED
[junit] Running org.custommonkey.xmlunit.test_XMLUnit
[junit] Tests run: 6, Failures: 0, Errors: 1, Time elapsed: 0.009 sec
[junit] TEST org.custommonkey.xmlunit.test_XMLUnit FAILED
[junit] Running org.custommonkey.xmlunit.test_XpathNodeTracker
[junit] Tests run: 7, Failures: 0, Errors: 4, Time elapsed: 0.004 sec
[junit] TEST org.custommonkey.xmlunit.test_XpathNodeTracker FAILED
[junit] Running org.custommonkey.xmlunit.util.test_IntegerBuffer
[junit] Tests run: 13, Failures: 0, Errors: 0, Time elapsed: 0.031 sec
[junit] Tests FAILED
[junitreport] Processing /home/user/Downloads/xmlunit/xmlunit-1.5/build/test-report/TESTS-TestSuites.xml to /tmp/null221785660
[junitreport] Loading stylesheet jar:file:/usr/share/ant/lib/ant-junit.jar!/org/apache/tools/ant/taskdefs/optional/junit/xsl/junit-frames.xsl
[junitreport] Warning: org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser: Property 'http://javax.xml.XMLConstants/property/accessExternalDTD' is not recognized.
[junitreport] Transform time: 884ms
[junitreport] Deleting: /tmp/null221785660
BUILD FAILED
/home/user/Downloads/xmlunit/xmlunit-1.5/build.xml:167: Some tests failed
Total time: 8 seconds
ant is version 1.8.2
junit is version 3.8.2
jdk is oracle and version 1.7
To your first question: java expects the full classname including the package name - but even then that's not how you run JUnit tests (see other thread). Please make yourself familiar with JUnit as XMLUnit 1.x expects you to know JUnit already.
Your second post says you face test failures when you try to run XMLUnit's tests. There may be several reasons for this - including bugs in XMLUnit - but nothing that should prevent you from running tests of your own.