SSD drives can support only a limited number of write cycles. During testing, data might get written repeatedly to a drive, but does not need to get saved long term. This stresses the SSD drive unnecessarily. Better use a RAM disk, which supports unlimited writes and benefit additionally from its higher speed.
Introduction
I got my new laptop, which has only SSD drives (solid-state drive). SSDs are faster than hard disks, but unfortunately, they don't really like being written to. When just one 1 bit needs to get set from 1 to 0, the poor SSD can't just do that. It has to take the block (typically between 256KB and 4MB), in which the bit to be overwritten resides, and copy the block with the changed bit(s) into an empty block, then has to erase the complete old block by applying a higher voltage. This stresses the SSD and SSDs support only a limited number of write cycles (typically between 3,000 and 100,000 writes).
Your unit tests are supposed to be run often. If possible, the test runs only using RAM. Unfortunately, this cannot always be achieved, especially when the test includes file processing or database access. In that case, it is better to use a RAM disk instead a SSD or HD drive.
A RAM disk behaves like a SSD or HD drive, but the data is only stored in RAM. RAM is much faster than SSD and it can be written to for a practically unlimited number of times. Unfortunately, Windows doesn't come with a RAM drive, but it is easy to install one.
Warning: Did ImDisk Make My PC Unstable ?
In the next chapter, I will recommend using ImDisk as RAM disk. However, few days after I published this article, my PC started to have strange errors, which may or may not be related to ImDisk. Since the Uninstall, I don't have errors again. That doesn't proof anything, but I thought I give a warning here. The unistall was easy. I would be curious to hear if others encountered problems as well. I guess sooner or later I give it a try again, but not right now.
RAM Disk Installation
A popular RAM disk toolkit is ImDisk. It uses the interesting WTFPL copyright: Do What the Fxxx You Want to Public License. Basically, it gives you the right to do anything with it. And it hasn't annoying advertisement.
I downloaded if from https://sourceforge.net/projects/imdisk-toolkit/. It comes in a zip file. Unzip and run install.bat. It runs an installer, which installs the driver and some utilities. I was just interested in the RAM disk and therefore started the RamDisk Configuration app.
You can install several RAM disks with different drive letters. Launch at Windows Startup is very convenient, the RAM disk starts when Windows starts and is always available.
Windows creates with every start a new RAM disk. Like any other drive, before the RAM disk can be used, it must be formatted. Quick Format is good enough.
I didn't change anything here. However, if you would like that the RAM disk has already some content when it starts, like an empty database, you can use Load Content from Image File or Folder for that purpose.
Once you press OK, you are done and the new RAM disk is running. The only thing you need to do now is to change the SSD/HD drive in your test software to the RAM disk,
Points of Interest
I use the RAM disk not just for unit tests. In my final application, I give the user a test mode. There he gets a copy of the actual application data and can try out various functions, without changing the actual data. Also, this copy gets stored in the RAM disk.
Furthermore, I often work on files for only a short while, like taking the screen shots for this article, processing them and uploading them to CodeProject. Using the RAM disk this becomes extremely fast, and best of it is that I don't need to clean up these files when I no longer need them, the RAM disk automatically loses them with the next Window start.
History
- 20th December, 2020: Initial version