I am wondering if there are any benefits / risks of (not) putting a licence on test code which mostly consists of unit tests. What do you think?

I am particularly interested in licensing under (L)GPL, Apache, MIT and BSD.

EDIT: The assumption is that non-test code is already published under some licence, but test code is not, so the question is whether to publish it and if so whether to put the same licence on it.

migrated from stackoverflow.com Nov 5 '11 at 5:36

This question came from our site for professional and enthusiast programmers.

  • Wouldn't tests be considered facts/data, which aren't subject to copyright or licensing in the first place? It's legal to copy an API, and I would guess it's also legal to use the same tests to verify that the implementation is correct? – endolith Dec 17 '13 at 20:58

I'm surprised that no-one has mentioned this already, but if you don't attach a license to your code, whether it be product or test code, then others have no rights over the code.

Licensing code is about giving rights to others that they would not normally have. Your test code is automatically covered by copyright (in most countries around the world) even if you don't explicitly attach a copyright notice. Being copyrighted, other people cannot use, distribute or derive from that code.

By attaching a license to your test code, you give people the right to use, distribute and/or modify that code in accordance with the license terms.

I would recommend that you distribute your test code with your product code, under the same license. This is simplest for everyone. It also means that if people want to submit patches to you, then they can run your unit tests before they sent you a patch, which should help weeding out patches which break things.


In commercial world, most companies charge not only for the core product but also for the support. Most often support involves any form of help by means of tool or personal assistance, to be able to make the product usable or resolve any issues related to product.

By this token, code for testing the product equally qualifies a support tool and is an intellectual property in its own right. So it does deserve a license of it's own.


Why do you separate code and test?

I prefer a bundle of code and test. And this bundle should get the same license.

If somebody would like to get twice money, then you may make two packages - each with a license. For free software, I see no reason for two packages (unless it is a size problem).


The test code has a lot of value, since it allows the user to check if your solution works in a given environnement. In my job (embedded software) the test suite is part of the contract. You should publish it with the same licence, because usage is similar:

  • if someone just uses your code, then he will run the tests

  • if someone wants to modify the code, he will probably have to modify some tests as well


IANAL, however:

  1. If you are licensing your code under GPL, then de facto your unit tests are also GPL as they're pretty useless without the main code
  2. If you're using Apache/BSD, the 'USE AT YOUR OWN RISK' provision. I'd slap a license file with the whole project and let the user figure out if it's for the code or the test code.
  3. If you use a commercial license and limit access to the code, why would you publish your tests in the first place? If you want to be sure, put a 'BY READING THE TEST CODE, YOU HEREBY AGREE TO GOUGE YOUR EYES' license and you're good to go.

The GCC compiler (mostly GPLv3 licensed) has a quite extensive test suite, which is distributed with the source code. (perhaps some test files are in the public domain, I really don't know their individual legal status).

Why would you want to distribute your test suite separately from your product?


It might be a possible business model so release a program as free software (GPL or whatever), but the appertaining unit tests under a commercial license. That way, if someone wants to release an improved version of your software (e.g. embedded in a device), he might be motivated to buy the unit test license for quicker and safer development.


If your unit tests are well done then they are a blueprint for reproducing your software. If you don't license them equivalently to the code you are inviting someone to just come along and re-implement whatever you did. If you are alright with that then don't bother licensing them.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.