How to check file handling

I heard that access to the database is incorrect during testing.

But what about file manipulation? Things like cp, mv, rmand touchmethods in FileUtils.

If I write a test and actually run commands (moving files, renaming files, creating directories, etc.), I can test them. But I need to โ€œcancelโ€ every command that I executed before running the test again. Therefore, I decided to write all the code for the "cancellation", but it seems like a waste of time, because I really do not need to "cancel".

I really want to see how others do it. How would you test, for example, when creating a large number of static files?

+3
source share
6 answers

In your case, access to files is completely completed, if you write file manipulation code, it should be tested on files. The only thing you should be careful about is that a failed test means that you are mistaken, and not that someone deleted the file needed for the test, or something like that. I would put the directory and files necessary for the tests in a separate folder, which is used only for the test. Then, when creating a test copy, the entire folder in a temporary place performs all testing, and then after the test deletes temporary files. Thus, each test has a blank copy of the files saved for the test.

+2
source

"" "" , , DB...

"" ( ) , .

, , Janusz, , mock FileUtils FileUtils .

+3

, , , smtp- .., . - , , , , . , , , , . , , .

, , , . , , .

+1

" ". ?

. , , . .

+1

RAM, . , `unix command` .

+1

Perhaps you could create a directory inside the test suite with the name "test_ *". Then the files that you change will be placed in this directory (for example: if you create a directory, you will create a directory inside the test directory). At the end of the test, you can delete this directory (with only one command). This is a unique UNDO operation that you perform.

You will put all the files you need in the test directory inside the test package.

0
source

Source: https://habr.com/ru/post/1725280/


All Articles