小编Pra*_*een的帖子

模拟 Microsoft Application Insights API

我有一个应用程序,它使用自定义跟踪/指标写入 App INsights ,还使用​​REST API将数据读取到仪表板上。 我的问题是对于我的单元测试,我可以模拟自定义跟踪(TelemetryClient)和 REST API 吗?

我看到 REST API 有一个演示版本,但提供随机信息。如果我可以设置一个 DEMO 仪器密钥来写入和读取它以进行单元测试,那将会很有帮助。让我知道。

unit-testing mocking azure azure-application-insights

6
推荐指数
1
解决办法
4655
查看次数

如何在运行时将字符串转换为整数

我在java中使用反射.

我开始知道我在运行时传递的方法参数的类型.所以我将文件中的参数值提取到字符串变量中.

现在,如果我知道参数类型为整数,如果我传递一个包含我得到的字符串值的对象

参数类型不匹配java.lang.IllegalArgumentException:参数类型不匹配

Class classDefinition = Class.forName("webservices."+objectName);

String methodName = set"+fieldNameAttay[i].substring(0,1)).toUpperCase()+fieldNameAttay[i].substring(1); Field f = classDefinition.getDeclaredField(fieldNameAttay[i]);

       try 
    {        
        //argType = f.getType();
              Method meth = classDefinition.getMethod(methodName,f.getType()); 

              Object arg = new Object[]{fieldValueArray[i]}; //fieldValueArray[i] is always string array 
                   meth.invoke(object, arg);   //If f.getType is Integer this //throws ex
                                   }
          catch (Exception e) 
          {
             System.err.println(e.getMessage());
             e.printStackTrace();
          }
Run Code Online (Sandbox Code Playgroud)

java reflection casting

1
推荐指数
1
解决办法
2837
查看次数