Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
Post History
When you think about how to organize your test code, you should develop an understanding of your goals. Typical goals about test code organization (which typically includes helper code only needed...
Answer
#4: Post edited
- When you think about how to organize your test code, you should develop an understanding of your goals. Typical goals about test code organization (which typically includes helper code only needed for the tests) are:
- * Ensure that test code does not become part of production code - for some kinds of software this can even be a strict requirement (for example in safety critical software) - even if the test code within the production code would be dead code or unreachable.
- * Ensure that in deliveries to the customer only the agreed parts are included, for example production code without tests or vice versa - depending on the contract.
* Make it easily possible to handle test code differently in tools (for example, test coverage tools, static code analysis tools), for example by excluding them by path or module name or the like. The possibility to exclude them during normal compilation (with the `#[cfg(test)]` annotation as was mentioned by @Moshi) is just one example for this.- * Especially in contexts where different kinds of tests have to be performed (unit-tests, integration tests, performance tests, ...) it may become a practical necessity to have the different kinds of code clearly separated and individually structured to avoid confusion even during development. You may need to make additional distinctions between short running and long running tests and so on.
- By grouping tests into a separated module or directory etc. you can fulfill the aforementioned goals - in some cases you will even have to go beyond that and introduce further substructuring.
- When you think about how to organize your test code, you should develop an understanding of your goals. Typical goals about test code organization (which typically includes helper code only needed for the tests) are:
- * Ensure that test code does not become part of production code - for some kinds of software this can even be a strict requirement (for example in safety critical software) - even if the test code within the production code would be dead code or unreachable.
- * Ensure that in deliveries to the customer only the agreed parts are included, for example production code without tests or vice versa - depending on the contract.
- * Make it easily possible to handle test code differently in tools (for example, test coverage tools, static code analysis tools), for example by excluding them by path or module name or the like. The possibility to exclude them during normal compilation (which the `#[cfg(test)]` annotation achieves, as was mentioned by @Moshi) is just one example for this.
- * Especially in contexts where different kinds of tests have to be performed (unit-tests, integration tests, performance tests, ...) it may become a practical necessity to have the different kinds of code clearly separated and individually structured to avoid confusion even during development. You may need to make additional distinctions between short running and long running tests and so on.
- By grouping tests into a separated module or directory etc. you can fulfill the aforementioned goals - in some cases you will even have to go beyond that and introduce further substructuring.
#3: Post edited
- When you think about how to organize your test code, you should develop an understanding of your goals. Typical goals about test code organization (which typically includes helper code only needed for the tests) are:
- * Ensure that test code does not become part of production code - for some kinds of software this can even be a strict requirement (for example in safety critical software) - even if the test code within the production code would be dead code or unreachable.
- * Ensure that in deliveries to the customer only the agreed parts are included, for example production code without tests or vice versa - depending on the contract.
* Make it easily possible to handle test code differently in tools (for example, test coverage tools, static code analysis tools), for example by excluding them by path or module name or the like.- * Especially in contexts where different kinds of tests have to be performed (unit-tests, integration tests, performance tests, ...) it may become a practical necessity to have the different kinds of code clearly separated and individually structured to avoid confusion even during development. You may need to make additional distinctions between short running and long running tests and so on.
- By grouping tests into a separated module or directory etc. you can fulfill the aforementioned goals - in some cases you will even have to go beyond that and introduce further substructuring.
- When you think about how to organize your test code, you should develop an understanding of your goals. Typical goals about test code organization (which typically includes helper code only needed for the tests) are:
- * Ensure that test code does not become part of production code - for some kinds of software this can even be a strict requirement (for example in safety critical software) - even if the test code within the production code would be dead code or unreachable.
- * Ensure that in deliveries to the customer only the agreed parts are included, for example production code without tests or vice versa - depending on the contract.
- * Make it easily possible to handle test code differently in tools (for example, test coverage tools, static code analysis tools), for example by excluding them by path or module name or the like. The possibility to exclude them during normal compilation (with the `#[cfg(test)]` annotation as was mentioned by @Moshi) is just one example for this.
- * Especially in contexts where different kinds of tests have to be performed (unit-tests, integration tests, performance tests, ...) it may become a practical necessity to have the different kinds of code clearly separated and individually structured to avoid confusion even during development. You may need to make additional distinctions between short running and long running tests and so on.
- By grouping tests into a separated module or directory etc. you can fulfill the aforementioned goals - in some cases you will even have to go beyond that and introduce further substructuring.
#2: Post edited
When you think about how to organize your test code, you should develop an understand of your goals. Typical goals about test code organization (which typically includes helper code only needed for the tests) are:- * Ensure that test code does not become part of production code - for some kinds of software this can even be a strict requirement (for example in safety critical software) - even if the test code within the production code would be dead code or unreachable.
- * Ensure that in deliveries to the customer only the agreed parts are included, for example production code without tests or vice versa - depending on the contract.
- * Make it easily possible to handle test code differently in tools (for example, test coverage tools, static code analysis tools), for example by excluding them by path or module name or the like.
- * Especially in contexts where different kinds of tests have to be performed (unit-tests, integration tests, performance tests, ...) it may become a practical necessity to have the different kinds of code clearly separated and individually structured to avoid confusion even during development. You may need to make additional distinctions between short running and long running tests and so on.
- By grouping tests into a separated module or directory etc. you can fulfill the aforementioned goals - in some cases you will even have to go beyond that and introduce further substructuring.
- When you think about how to organize your test code, you should develop an understanding of your goals. Typical goals about test code organization (which typically includes helper code only needed for the tests) are:
- * Ensure that test code does not become part of production code - for some kinds of software this can even be a strict requirement (for example in safety critical software) - even if the test code within the production code would be dead code or unreachable.
- * Ensure that in deliveries to the customer only the agreed parts are included, for example production code without tests or vice versa - depending on the contract.
- * Make it easily possible to handle test code differently in tools (for example, test coverage tools, static code analysis tools), for example by excluding them by path or module name or the like.
- * Especially in contexts where different kinds of tests have to be performed (unit-tests, integration tests, performance tests, ...) it may become a practical necessity to have the different kinds of code clearly separated and individually structured to avoid confusion even during development. You may need to make additional distinctions between short running and long running tests and so on.
- By grouping tests into a separated module or directory etc. you can fulfill the aforementioned goals - in some cases you will even have to go beyond that and introduce further substructuring.
#1: Initial revision
When you think about how to organize your test code, you should develop an understand of your goals. Typical goals about test code organization (which typically includes helper code only needed for the tests) are: * Ensure that test code does not become part of production code - for some kinds of software this can even be a strict requirement (for example in safety critical software) - even if the test code within the production code would be dead code or unreachable. * Ensure that in deliveries to the customer only the agreed parts are included, for example production code without tests or vice versa - depending on the contract. * Make it easily possible to handle test code differently in tools (for example, test coverage tools, static code analysis tools), for example by excluding them by path or module name or the like. * Especially in contexts where different kinds of tests have to be performed (unit-tests, integration tests, performance tests, ...) it may become a practical necessity to have the different kinds of code clearly separated and individually structured to avoid confusion even during development. You may need to make additional distinctions between short running and long running tests and so on. By grouping tests into a separated module or directory etc. you can fulfill the aforementioned goals - in some cases you will even have to go beyond that and introduce further substructuring.