Tests not running properly - Android

I'm facing a problem when running tests on my project. I'm using JUnit, Mockito and PowerMock.

I have a test class which I can run from Android Studio and works well (6 out of 6 working). But, if instead of doing it from AS i use the command ./gradlew test three of them are failing with the error:

java.lang.NoClassDefFoundError at MyTestsClass.java:166

Searching that line I can see that's calling a method (so I suppose the error is not exactly there but inside the call, somewhere).

How can it be failing from the command and working from AS? What's the difference between this two? What could it be causing that error?

Upvotes: 1

Views: 201

Answers (1)

Óscar
Óscar

Reputation: 726

It could be because of your dependencies.

You don't have them defined on the test it won't compile. For example:

// Needed to compile    
compileOnly 'com.madgag.spongycastle:prov:1.54.0.0'

// Needed to compile tests
testImplementation 'com.madgag.spongycastle:prov:1.54.0.0'

Could it be?

Upvotes: 1

Related Questions