Library throws AssertionError making my tests fail

591 views Asked by At

I've been working on creating a unit test for my java project, and my test keeps on failing even if I made no assertions.

After reading through the stacktrace, I noticed that a method in the retsIQ library I am using is throwing an assertion error. Is there anyway I can ignore this? I'd really rather not decompile and recompile the module.

I should also mention that this exact code works fine if it's not run as a test.

Here is a picture of my test: Unit Test

Here is a picture of it it not running in a test: enter image description here

2

There are 2 answers

0
Roman On

I'll assume two things: 1) your project is maven-based; 2) those two code fragments are exactly the same (except for the assertTrue(true); line, which does nothing, by the way).

Maybe your problem is caused by the fact that "run" and "test" configurations have different classpaths. You may have a wrong version of some library in the test classpath or even miss some library, which eventually leads to this exception.

I suggest you re-check all test-scoped dependencies in pom.xml. You can also print project dependency tree using Maven Dependency Plugin (but I'm not sure whether it can print test dependencies separately):

mvn dependency:tree -Dverbose

Alternatively you can go to "Project Structure" > "Modules" > "Dependencies" tab in Intellij Idea and look through all entries with "Test" scope.

0
NamshubWriter On

From the stacktrace, it looks like there is unexpected data found when parsing the response. The best way to diagnose the problem would set a breakpoint in SearchCompactReader.parse() (around line 16), and run the test in the debugger.

BTW, your test isn't a unit test. A unit test tests a single class or method in isolation. Your test appears to be hitting a live server.