From 46f6c953a1a529ac4ffe69dab163ae5e92dba415 Mon Sep 17 00:00:00 2001 From: renpengfei Date: Mon, 19 Jul 2021 10:13:55 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=94=B9=E5=8D=95=E5=85=83=E6=B5=8B?= =?UTF-8?q?=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../shadowlayoutexample/ExampleOhosTest.java | 73 +++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/entry/src/ohosTest/java/com/lijiankun24/shadowlayoutexample/ExampleOhosTest.java b/entry/src/ohosTest/java/com/lijiankun24/shadowlayoutexample/ExampleOhosTest.java index e87822a..30a2e23 100644 --- a/entry/src/ohosTest/java/com/lijiankun24/shadowlayoutexample/ExampleOhosTest.java +++ b/entry/src/ohosTest/java/com/lijiankun24/shadowlayoutexample/ExampleOhosTest.java @@ -18,6 +18,9 @@ package com.lijiankun24.shadowlayoutexample; import ohos.aafwk.ability.delegation.AbilityDelegatorRegistry; import org.junit.Test; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + import static org.junit.Assert.assertEquals; /** @@ -35,4 +38,74 @@ public class ExampleOhosTest { final String actualBundleName = AbilityDelegatorRegistry.getArguments().getTestBundleName(); assertEquals("com.lijiankun24.shadowlayoutexample", actualBundleName); } + + /** + * test加 + */ + @Test + public void testAdd(){ + try { + Class numberUtil = Class.forName("com.lijiankun24.shadowlayout.NumberUtil"); + Method add = numberUtil.getMethod("add", double.class, double.class); + Object obj = numberUtil.getConstructor().newInstance(); + int invoke = (int) add.invoke(obj,1.0,1.0); + assertEquals(2,invoke); + } catch (InstantiationException | InvocationTargetException | + NoSuchMethodException | IllegalAccessException | ClassNotFoundException e) { + e.printStackTrace(); + } + } + + /** + * test减 + */ + @Test + public void testSub(){ + try { + Class numberUtil = Class.forName("com.lijiankun24.shadowlayout.NumberUtil"); + Method sub = numberUtil.getMethod("sub", double.class, double.class); + Object obj = numberUtil.getConstructor().newInstance(); + int invoke = (int) sub.invoke(obj,2.0,1.0); + assertEquals(1,invoke); + } catch (InstantiationException | InvocationTargetException | + NoSuchMethodException | IllegalAccessException | ClassNotFoundException e) { + e.printStackTrace(); + } + } + + /** + * test乘 + */ + @Test + public void testMul(){ + try { + Class numberUtil = Class.forName("com.wuhenzhizao.sku.utils.NumberUtil"); + Method mul = numberUtil.getMethod("mul", double.class, double.class); + Object object = numberUtil.getConstructor().newInstance(); + int invoke = (int) mul.invoke(object, 1, 2); + assertEquals(2,invoke); + } catch (InstantiationException | InvocationTargetException | + NoSuchMethodException | IllegalAccessException | ClassNotFoundException e) { + e.printStackTrace(); + } + } + + /** + * test除 + */ + @Test + public void testDiv(){ + try { + Class numberUtil = Class.forName("com.wuhenzhizao.sku.utils.NumberUtil"); + Method div = numberUtil.getMethod("div", double.class, double.class); + Object object = numberUtil.getConstructor().newInstance(); + int invoke = (int) div.invoke(object, 2, 2); + assertEquals(1,invoke); + } catch (InstantiationException | InvocationTargetException | + NoSuchMethodException | IllegalAccessException | ClassNotFoundException e) { + e.printStackTrace(); + } + } + + } \ No newline at end of file -- Gitee