From f97ea2d17345a71be8457600240de31697184200 Mon Sep 17 00:00:00 2001 From: jjLv <1981429112@qq.com> Date: Fri, 25 Jul 2025 16:52:42 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AC=AC=E4=B8=80=E6=AC=A1=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../canteen/ExampleInstrumentedTest.java | 44 +++++++++++++++ .../com/bonus/canteen/ExampleUnitTest.java | 53 +++++++++++++++++++ 2 files changed, 97 insertions(+) create mode 100644 app/src/androidTest/java/com/bonus/canteen/ExampleInstrumentedTest.java create mode 100644 app/src/test/java/com/bonus/canteen/ExampleUnitTest.java diff --git a/app/src/androidTest/java/com/bonus/canteen/ExampleInstrumentedTest.java b/app/src/androidTest/java/com/bonus/canteen/ExampleInstrumentedTest.java new file mode 100644 index 0000000..e2c3d82 --- /dev/null +++ b/app/src/androidTest/java/com/bonus/canteen/ExampleInstrumentedTest.java @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2025 xuexiangjys(xuexiangjys@163.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package com.bonus.canteen; + +import android.content.Context; + +import androidx.test.platform.app.InstrumentationRegistry; +import androidx.test.runner.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.*; + +/** + * Instrumented test, which will execute on an Android device. + * + * @see Testing documentation + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + @Test + public void useAppContext() { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); + + assertEquals("com.bonus.canteen", appContext.getPackageName()); + } +} diff --git a/app/src/test/java/com/bonus/canteen/ExampleUnitTest.java b/app/src/test/java/com/bonus/canteen/ExampleUnitTest.java new file mode 100644 index 0000000..03ebb7e --- /dev/null +++ b/app/src/test/java/com/bonus/canteen/ExampleUnitTest.java @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2025 xuexiangjys(xuexiangjys@163.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package com.bonus.canteen; + +import com.bonus.canteen.core.http.entity.TipInfo; +import com.xuexiang.xhttp2.model.ApiResult; +import com.xuexiang.xutil.net.JsonUtil; + +import org.junit.Test; + +import java.util.ArrayList; +import java.util.List; + +import static org.junit.Assert.*; + +/** + * Example local unit test, which will execute on the development machine (host). + * + * @see Testing documentation + */ +public class ExampleUnitTest { + @Test + public void addition_isCorrect() { + assertEquals(4, 2 + 2); + + + TipInfo info = new TipInfo(); + info.setTitle("微信公众号"); + info.setContent("获取更多资讯,欢迎关注我的微信公众号:【我的Android开源之旅】"); + List list = new ArrayList<>(); + for (int i = 0; i <5 ; i++) { + list.add(info); + } + ApiResult> result = new ApiResult<>(); + result.setData(list); + System.out.println(JsonUtil.toJson(result)); + } +} \ No newline at end of file