* limitations under the License.
 */package android.location.cts;import dalvik.annotation.TestLevel;
import dalvik.annotation.TestTargetClass;
import dalvik.annotation.TestTargetNew;import android.content.Context;
import android.location.GpsSatellite;
import android.location.GpsStatus;
import android.location.LocationManager;
import android.test.AndroidTestCase;import java.util.Iterator;
import java.lang.*;@TestTargetClass(GpsSatellite.class)
public class GpsSatelliteTest extends AndroidTestCase {
    private GpsSatellite mGpsSatellite;    @Override
    protected void setUp() throws Exception {
        super.setUp();
        LocationManager lm =
            (LocationManager) getContext().getSystemService(Context.LOCATION_SERVICE);
        GpsStatus gpsStatus = lm.getGpsStatus(null);        Iterator<GpsSatellite> iterator = gpsStatus.getSatellites().iterator();
        if (iterator.hasNext()) {
            mGpsSatellite = iterator.next();
        }
    }
    @TestTargetNew(
        level = TestLevel.COMPLETE,
        method = "getAzimuth",
        args = {}
    )
   public void testGetAzimuth() throws Exception{
       
String a=new String();
if(mGpsSatellite != null) {
a=String.format("%1.4f",mGpsSatellite.getAzimuth());
}
//+mGpsSatellite.getAzimuth();
            fail("&&&&&&&&&&&&&&&&&&"+a);
    }    @TestTargetNew(
        level = TestLevel.COMPLETE,
        method = "getElevation",
        args = {}
    )
    public void testGetElevation() {
        if (mGpsSatellite != null) {
            assertTrue(mGpsSatellite.getElevation() >= 0 && mGpsSatellite.getElevation() <= 90);
        }
    }    @TestTargetNew(
        level = TestLevel.COMPLETE,
        method = "getPrn",
        args = {}
    )
    public void testGetPrn() {
        if (mGpsSatellite != null) {
            // make sure there is no exception.
            mGpsSatellite.getPrn();
        }
    }    @TestTargetNew(
        level = TestLevel.COMPLETE,
        method = "getSnr",
        args = {}
    )
    public void testGetSnr() {
        if (mGpsSatellite != null) {
            // make sure there is no exception.
            mGpsSatellite.getSnr();
        }
    }    @TestTargetNew(
        level = TestLevel.COMPLETE,
        method = "hasAlmanac",
        args = {}
    )
    public void testHasAlmanac() {
        if (mGpsSatellite != null) {
            // make sure there is no exception.
            mGpsSatellite.hasAlmanac();
        }
    }    @TestTargetNew(
        level = TestLevel.COMPLETE,
        method = "hasEphemeris",
        args = {}
    )
    public void testHasEphemeris() {
        if (mGpsSatellite != null) {
            // make sure there is no exception.
            mGpsSatellite.hasEphemeris();
        }
    }    @TestTargetNew(
        level = TestLevel.COMPLETE,
        method = "usedInFix",
        args = {}
    )
    public void testUsedInFix() {
        if (mGpsSatellite != null) {
            // make sure there is no exception.
            mGpsSatellite.usedInFix();
        }
    }
}
这是基于junit测试的一个程序,我想通过修改获取到mGpsSatellite.getAzimuth()和mGpsSatellite.getElevation()的值,在junit中只能通过assert和fail等方法来捕捉到,请问我该如何修改,其中这两个值都是float类型的。而assert和fail输出都要求String型的

解决方案 »

  1.   

    "" + floatValue 就可以。
      

  2.   

    还是不行  junit里没有这个函数
    cts/tests/tests/location/src/android/location/cts/GpsSatelliteTest.java:57: cannot find symbol
    symbol  : method floatvalue(float)
    location: class android.location.cts.GpsSatelliteTest
    a="!!!!!!!!!!!!"+floatvalue(mGpsSatellite.getAzimuth());
                     ^
    1 error
    make: *** [out/target/common/obj/APPS/CtsLocationTestCases_intermediates/classes-full-debug.jar] Error 41