question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to load test resource immediately after clean

See original GitHub issue

steps

  1. Clone the demonstration repository
  2. Run demo.sh

The output we’re seeing is in the README of the demonstration repository.

problem

The test in the demo tries to load a file from test resources using Thread.currentThread.getContextClassLoader:

  • When the tests run immediately after a clean, the test fails because the resource can’t be found.
  • In subsequent sbt executions, the tests pass.

expectation

Code in the test scope should always be able to load resources from src/test/resources, whether immediately after a clean or not.

notes

sbt version: 1.0.0 and 1.0.1

Running the demo script with build.properties setting sbt.version=0.13.16 works as expected.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
eed3si9ncommented, Aug 17, 2018

Based on Rafal’s analysis I am going to call it a Specs2 issue.

0reactions
ravwojdylacommented, Dec 21, 2017

It seems like this is related to how specs2 works, reasoning:

  • thread pool created by specs2 might not have valid ClassLoader in which case the tests will fail. I have not looked into code of specs2, but their ThreadPool most likely inherits ClassLoader from the parent thread, in which case it would depend on whatever is the state of the parent thread (which might explain why it sometimes works, and sometimes doesn’t)
  • can’t reproduce this problem in scalatest, which uses the same thread as sbt to execute test code (which ensures that ContextClassLoader is valid for the duration of the test, here)
Read more comments on GitHub >

github_iconTop Results From Across the Web

java - Junit test fail on maven clean install - load a file in test ...
Your testfile.txt resource is in the right place. This should work unless you have custom Maven resource filtering rules e.g. to exclude .txt ......
Read more >
Quickstart: Create and run a load test with Azure Load Testing
This quickstart shows how to create an Azure Load Testing resource and run a high-scale load test for an external website by using...
Read more >
Test task unable to locate the resource under target as target ...
Test task is failing. As its unable to find the resource file required (I am trying to load the resource file using ClasspathStoryFinder.class....
Read more >
Test fixtures - testthat
and “Who didn't clean up after the dog?”. It's also important that your setup and cleanup is easy to use when working interactively....
Read more >
Explore test results | IntelliJ IDEA Documentation - JetBrains
After IntelliJ IDEA finishes running your tests, it shows the results ... on the test execution and why your tests failed or were...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found