lvthillo
lvthillo

Reputation: 30851

android tests fail in jenkins

I've setup a CI-server on Jenkins that will automize the build of an Android-app. When I skip the tests everything works fine.

clean build -x test

and I will receive apk's and a build which is finished with succes. But when I'm not skipping the tests I get an error. My command is:

clean build

And I will get the following error:

    :app:testDebug

    Test > testnamse FAILED
        java.lang.NoClassDefFoundError
            Caused by: java.lang.ClassNotFoundException

   Test > testname FAILED
        java.lang.NoClassDefFoundError

    Test > testname FAILED
        java.lang.NoClassDefFoundError

    ...

    8 tests completed, 8 failed
    :app:testDebug FAILED

    FAILURE: Build failed with an exception.

    * What went wrong:
    Execution failed for task ':app:testDebug'.
    > There were failing tests. See the report at: file:index.html

This .html shows the failed tests and the java.lang.NoClassDefFoundError. But the tests succeeded when the developer executed them with gradle on his local machien. They use gradle 2.2.1 while I'm using gradle 2.3 on the server. I don't know if that's an issue.

Upvotes: 0

Views: 1272

Answers (2)

lvthillo
lvthillo

Reputation: 30851

This was the solution: Add testCompile 'org.apache.maven:maven-ant-tasks:2.1.3' in your app/build.gradle between the dependencies - tags.

Upvotes: 0

Anthony
Anthony

Reputation: 3074

Judging by what your saying, I will assume that you are using some form of Source Control similar to GitHub. It is worth checking your repository and your ".ignore" file (if you are using GitHub).

An example of a good .ignore file would be something like this:

# Built application files
*.apk
*.ap_

# Files for the Dalvik VM
*.dex

# Java class files
*.class

# Generated files
bin/
gen/

# Gradle files
.gradle/
build/
/*/build/

# Local configuration file (sdk path, etc)
local.properties

# Proguard folder generated by Eclipse
proguard/

# Log Files
*.log

I have a feeling like your .jar files are not included in a check in, thus when Jenkins tried to build your .apk it cannot find the .jar files required and then fails. Your developers have the .jar files which is why they can compile the program. You should ask your developers to check the git.ignore (or similar) and fix it so that it looks like mine above. Check everything in, then try to build once more.

Upvotes: 1

Related Questions