I wrote a JUnit test that validates the xml returned by a service against its XSD. I initially put the XSD under src/main/resrouces/xsd/<filename>.xsd
But now I'm facing the need to move it under webapp
, as a static resource, so that it will be publicly accessible when the application is deployed.
I'd rather not have two copies, as I expect that somebody will modify the wrong one sooner or later.
I was loading the file with getClass().getResource("/xsd/<filename>.xsd")
, how would I access it if the resource is moved under webapp
?
Which methods cannot be tested by the JUnit test class? Explanation: When a method is declared as “private”, it can only be accessed within the same class. So there is no way to test a “private” method of a target class from any JUnit test class.
If a JUnit test method is declared as "private", it compiles successfully. But the execution will fail. This is because JUnit requires that all test methods must be declared as "public".
What is a Façade in JUnit? Explanation: Façade defines a higher-level interface that makes the subsystem easier to use.
/src/main/webapp
contents are placed on the CLASSPATH when WAR is created and deployed, but not during JUnit tests (both in maven and in my IDE). You have to load them explicitly using:
new File("src/main/webapp/xsd/<filename>.xsd");
This should work as long as project main directory is the current directory while running tests. Sad but true.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With