簡體   English   中英

haskell自動化測試配置

[英]haskell automated test configuration

我已經建立了一個項目,我想為此編寫測試。 現在的問題是我在使用數據庫的生產環境中的功能,但是在測試中,我想將它們定向到偽數據庫。

例如,我有字符串mongoHostAdress = "192.168.0.1" ,我的函數使用該字符串訪問mongo數據庫,而我在測試時希望將其更改為mongoHostAdress = "127.0.0.1"

如何告訴Haskell自動為我執行此操作?

編輯:更一般的前景

如何為項目創建配置文件,並在項目的不同階段使用不同的參數?

因此,概念是創建文件input.txt,如下所示:

fstParameterName:fstParameterValue
sndParameterName:sndParameterValue
trdParameterName:trdParameterValue

現在在main函數中,您可以使用如下構造輕松地設置參數:

main = do
text <- readFile "input.txt"
mongoHostAdress <- (getConfigValue "mongoHostAdress" (lines text))
print(mongoHostAdress)

getConfigValue name (l:ls) = if(containsPrefix name l) 
  then (return(skipPrefix name l))
  else (getConfigValue name ls)

containsPrefix [] x = True
containsPrefix (x:xs) (y:ys) = if(x==y) then (containsPrefix xs ys) else False

skipPrefix [] (x:xs) = xs --x is just ":" and ofc we dont want it
skipPrefix (x:xs) (y:ys) = skipPrefix xs ys

暫無
暫無

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

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