The method I've found to be the most useful for testing the same code against multiple versions of Sitecore, is to setup with the use of Sitecore Instance Manager a starting website instance, such as 8.2.5. Once that is setup, I will start creating my Visual Studio Solution. I will then use Gulp to create a Libraries folder in the same folder as my solution:
gulp.task('Copy-Sitecore-Dlls', function () {
fs.statSync(config.sitecoreLibraries);
var files = config.sitecoreLibraries + "/**/*";
var libs = gulp.src(files).pipe(gulp.dest("./libraries"));
return merge(libs);
});
config.sitecoreLibraries
just has the path to my SIM instances bin folder.
Make sure you never commit this libraries folder however, and configure it in your gitignore file. Once you have that, you can then reference dlls that are in that libraries folder for the kernel. If you originally setup 8.2.5 and you have tested it against that, you can now setup with the help of SIM or the install framework (if you are wanting to test against 9.0+) new instances, and then all you need to do is change your gulp config to target this new instance. Once configured you can bring in the version specific dlls into your solution and confirm it'll still build and work with those different versions of the dll's.
Now if you found that you had to make specific changes for a specific version, such as code specific to 8.2 or 9.0 for example, you can create new branches in your source control to contain the releases for those specific versions. So you might end up with a release of your project for 9.0 specifically.