I am using Simpletests for my site which check for file upload functionality. The problem is that uploading files requires sites/*/files to be owned by the web user (www in my case). When running simpletests, files are uploaded to a temporary directory sites/*/files/simpletest/*, which also needs to be owned by the web user (www).
When running your tests via the command line (in my case with the user jenkins), your command-line user needs to be able to write to sites/*/files/simpletest.
My solution has been to use the visudo file to allows jenkins to run drush under the www user (on a test environment), and then run my tests in the command but under www.
sudo -u _www drush test-run 'mysite deploy' -y
To avoid permissions problems, sites/*/files/simpletest must also be owned by www, but jenkins needs to be in a group that has write access to that directory.