2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

[JMeter]CSVファイル読み込みに応じたAPI繰り返し実行方法 メモ

Posted at
  • JMeterでCSVファイルで一覧化しているIDリストを読み込み、APIリクエストを繰り返し実行したかったので、その方法を個人用にメモしておく。

テスト用API

  • パスパラメータに指定したユーザーIDをそのまま取得結果として返却するAPI

  • コード※Python/FastAPI製

    import uvicorn
    from fastapi import FastAPI
    import uuid
    import datetime
    app = FastAPI()
    
    @app.get("/v1/users/{user_id}")
    def users(user_id):
        user = {
            "user_id":user_id,
            "time":str(datetime.datetime.now())
        }
        return user
    
    
    if __name__ == "__main__":
        uvicorn.run(app, port=8000, loop="asyncio")
    

テストデータ

  • user_list.csv

    user_id
    ABCDE12345
    FGHIJ67890
    XXXXX98765
    

設定手順

  1. Thread Group に While Controllerを追加(Add -> Logic Controller -> While Controller)

    jm_while.png

  2. Wihle controller の Conditionに以下を設定

    ${__javascript("${user_id}" != "",)}
    

    ※変数user_idが空でない間繰り返す

  3. Wihle controller 配下にCSV Data Set Configを追加(Add -> Config Element -> CSV Data Set Config)

  4. CSV Data Set Configを下記のように設定

    jm_csv.png

  5. Wihle controller 配下にHTTP Requestを追加(Add -> Sampler -> HTTP Request)

  6. HTTP Requestを下記のように設定

    jm_http.png

動作確認

  • テスト用API起動

    uvicorn main:app --reload --host 0.0.0.0 --port 8000
    
  • Jmeter実行

    ※以下のようにuser_list.csvにあるユーザーID分APIが実行される。

    jm_result.png

参考情報

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?