How to create dummy files w.r.t different file size for testing in windows


During the test, we encounter multiple features that need to be tested against multiple file sizes to ensure verification of the boundary value analysis. 

It’s really easy to generate multiple files with different file sizes using PowerShell;  you may refer to the command below: 

$out = new-object byte[] Value_in_byte; (new-object Random).NextBytes($out); [IO.File]::WriteAllBytes('OutPut file path', $out)

Value_in_byte: You need to mention the value in byte.
OutPut file path: This refers to the path where the output file should be generated.

Examples

To generate a 1MB file:

$out = new-object byte[] 1048576 ; (new-object Random).NextBytes($out); [IO.File]::WriteAllBytes('D:\TestData\sample1by.txt', $out)

To generate a 10MB file: 

$out = new-object byte[] 10485760; (new-object Random).NextBytes($out); [IO.File]::WriteAllBytes('D:\TestData\sample1by.txt', $out)

To generate a 100MB file: 

$out = new-object byte[] 104857600; (new-object Random).NextBytes($out); [IO.File]::WriteAllBytes('D:\TestData\Sample100mb.txt', $out)

To generate a 1GB file:

$out = new-object byte[] 1073741824; (new-object Random).NextBytes($out); [IO.File]::WriteAllBytes('D:\TestData\sample1gb.txt', $out)

Note: We can generate any file-type by changing the file extension. 

To generate a 1GB file:

$out = new-object byte[] 1073741824; (new-object Random).NextBytes($out); [IO.File]::WriteAllBytes('D:\TestData\sample1gb.pdf', $out)

Leave A Comment

Your email address will not be published. Required fields are marked *