对字符串做正则表达式的比较,只比较字符串,不对字符串的值进行比对

   public boolean compareRegexString(String testName, String wsValue, String expectValue) {
        boolean result = false;
        String resultInfo = LR;
        resultInfo += "WS: " +wsValue+ LR;
        resultInfo += "Expect: " +expectValue+ LR;
        /**
         * 接下来是判断和记录结果过程
         */
        if ((expectValue == null || expectValue.length() == 0) && (wsValue == null || wsValue.length() == 0)) {
            result = true;
            resultInfo = PASS + LR + resultInfo;
        } else {
            Pattern pattern = Pattern.compile(expectValue);
            Matcher matcher = pattern.matcher(wsValue);
            result = matcher.find();
            if (result == true) {
                resultInfo = PASS + LR + resultInfo;
                Assert.assertTrue(result);
            } else {
                resultInfo = FAIL + LR + resultInfo;
                Assert.assertEquals(wsValue, expectValue);
            }
        }
        setStrResultInfo(resultInfo);
        writeReportResultInfo(result);
//            writeLog(testName);
        getReturnMap().put(testName, wsValue);
        return result;
    }

wsValue= {"code":"10000","msg":null,"data":{"untilnow_pv":0.007830058221967192,"DirectUsage":0.007830058222127264,"Charges_pv":0.007812278694385896,"Feedin_pv":0.0}}
expectValue="untilnow_pv":\S+,"DirectUsage":\S+,"Charges_pv":\S+,"Feedin_pv":\S+

  

posted on 2017-11-20 14:12  hong_0632  阅读(1786)  评论(0编辑  收藏  举报

导航