Frage

I wrote an API java class for our website, and the file API.java lives inside an Android Library Project so that we can utilize it in our Android apps. The file itself contains no Android-specific code however and is meant to be a general Java API for the site.

I want to add automated testing of this class using JUnit, the test should be executed through a shell script. Here is my script as it stands:

#!/bin/sh                                                                                      
echo Starting test...
java -cp ./Android/iSENSE\ Imports/lib/junit-4.10.jar \
org.junit.runner.JUnitCore ./Android/iSENSE\ Imports/src/edu/uml/cs/isense/test/APITest.java
echo Test complete!

I've tried many variations on the path/name for the file to be tested. My output from execution:

Starting test...
JUnit version 4.10
Could not find class: ./Android/iSENSE\ Imports/src/edu/uml/cs/isense/test/APITest.java

Time: 0.001

OK (0 tests)

Test complete!

I'm not sure on how to make JUnit find my APITest file to run it. Any thoughts?

War es hilfreich?

Lösung

I figured it out! I had to point the classpath to the compiled jar file for the Android library project, which lives in the bin folder, and then provide JUnit with the fully qualified name of the class. My final script looks as follows:

#!/bin/sh                                                                                                                  
echo Starting test...
cd ./Android/iSENSE\ Imports/
java -cp ./bin/isense\ imports.jar:./lib/junit-4.10.jar \
org.junit.runner.JUnitCore edu.uml.cs.isense.test.APITest
echo Test complete!
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top