簡體   English   中英

如何用phpunit測試字符串

[英]how to test a string with phpunit

我正在創建這個字符串

'Your maximum heart rate is ' . $int . ' Your body mass index is ' . $float . ' Your body fat percentage is ' . $float '%.'

然后退回

我的主張是

$stringFormat = 'Your maximum heart rate is %d. Your body mass index is %f.  Your body fat percentage is %f%.';

        $this->assertStringMatchesFormat($stringFormat, $actualResultm, 'message');

當測試運行時,我得到這個錯誤

FatControllerTest::testBodyInfo
message
Failed asserting that format description matches text.
--- Expected
+++ Actual
@@ @@
-Your maximum heart rate is %d. Your body mass index is %f.  Your body fat percentage is %f%.
+Your maximum heart rate is 193. Your body mass index is 43.181818181818. Your body fat percentage is 6.32302%.

現在,我想它必須與以下事實有關:我告訴它期望一個無符號的int和兩個浮點,並且它返回一個長字符串,但是如果是這種情況,我該如何測試一個字符串,就像我列出的那樣會有3個因案例而異的區域? 如果不是那樣,那我做錯了什么?

我想你有兩倍的空間。

$stringFormat = 'Your maximum heart rate is %d. Your body mass index is %f.  Your body fat percentage is %f%.';
                                                                            ^ extra space

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM