How to do integration testing in .NET with real files?

后端 未结 5 1058
孤独总比滥情好
孤独总比滥情好 2020-12-23 09:17

I have some classes that implements some logic related to file system and files. For example, I am performing following tasks as part of this logic:

  • checking i
5条回答
  •  被撕碎了的回忆
    2020-12-23 09:50

    I'd go with single test folder. For various test cases you can put different valid/invalid files into that folder as part of context setup. In test teardown just remove those files from folder.

    E.g. with Specflow:

    Given configuration file not exist
    When something
    Then foo
    
    Given configuration file exists
    And some dll not exists
    When something
    Then bar
    

    Define each context setup step as copying/not copying appropriate file to your folder. You also can use table for defining which file should be copied to folder:

    Given some scenario
    | FileName         |
    | a.config         |
    | b.invalid.config |
    When something
    Then foobar
    

提交回复
热议问题