Unable to access test resources from junit tests

zyd :

Edit: Turns out I hadn't rebuilt the program in a while. If all the other answers for this kind of problem are not working for you, try rebuilding! Thanks Timo!

I've looked at a ton of answers and tried a bunch of stuff. I know I must be doing something extremely minor wrong. If anyone has a quick tip please let me know, this is slowly killing me.

My directory setup is: enter image description here

I'm trying to read in testDom.xml with

File testFile = new File(getClass().getResource("testDom.xml").getFile());

I've tried loading from the class:

File testFile = new File(GemsDomGetChildrenTest.class.getResource("testDom.xml").getFile());

I've tried both with the path as

/lambda-compiler/src/test/resources/testDom.xml
/src/test/resources/testDom.xml
/test/resources/testDom.xml
/resources/testDom.xml
/testDom.xml
testDom.xml

And I've tried all those paths without leading '/' as well.

The resources folder also seems to be added as a test resource in IntelliJ too:

enter image description here

I get that this is probably a duplicative question and has been asked a million times, but I'm really struggling to see what I'm doing differently than all the other questions I've viewed so far. Any help would be greatly appreciated.

zyd :

Alright so Timo was able to figure it out. I hadn't rebuilt the project for a while (:facepalm:). Coming from the python world here, where things are a little different. Thanks for working through this with me everyone, it really means a lot!

Este artículo se recopila de Internet, indique la fuente cuando se vuelva a imprimir.

En caso de infracción, por favor [email protected] Eliminar

Editado en
0

Déjame decir algunas palabras

0Comentarios
Iniciar sesiónRevisión de participación posterior

Artículos relacionados

JUnit adding extra tests to Test Case

How do I run JUnit tests during my Ant build script while omitting test classes from my resulting jar?

Test-resources path on Windows in Java unit tests

Tests junit paramétrés avec plus d'un test

Why does a companion object not test as private field with JUnit tests?

Плагин Jenkins JUnit Test Result Report сообщает, что с шаблоном '** / unit-tests.xml' были найдены 4 файла (ов) отчета о тестировании?

Unable to run testNG tests from maven

import a test interface from a library's tests into application's tests

JUnit test для веб-сайта содержит одну строку или (исключая) другую строку

¿Cómo obtener la ruta del directorio src / test / resources en JUnit?

AWS Device Farm: APPIUM_JAVA_JUNIT_TEST_PACKAGE_CLASS_FILE_MISSING_IN_TESTS_JAR

Refactoriser les tests JUnit pour les étendre à plusieurs méthodes et cas de test

Spring Boot 1.4 test loading yaml file from main resources

Get custom method annotation value from junit test

Unable to Access Object Sender Parameter From If Statement

Unable to Access Local Host From Docker Container

Unable to Access Object Sender Parameter From If Statement

¿Por qué no puedo acceder a src / test / resources en la ejecución de prueba de Junit con Maven?

How to access session data from test?

Spring Parameterized / Theories JUnit Tests

Running JUnit Tests on a Restlet Router

System.setProperty in JUnit tests

No tests found for given includes: JUNIT

Unable to mock a function call from a function call from the test function

Creating Junit Test With IntelliJ

junit test is failing with exception

Maven not running JUnit test

Как сделать Java ServiceActivator видимым в JUnit Test?

Java Junit Test с Hamcrest: невозможно создать композиционный сопоставитель