Home  >  Article  >  Backend Development  >  How to Share Test Utility Functions Between Packages?

How to Share Test Utility Functions Between Packages?

Susan Sarandon
Susan SarandonOriginal
2024-11-03 23:40:30264browse

How to Share Test Utility Functions Between Packages?

How to Share Test Utility Functions Between Packages

Q: "How to reuse test code in imported packages?"

A1: It is generally advisable to move utility functions used in testing across multiple packages to a separate "utils" package and import this package in your *_test.go files.

However, if the utility functions rely on private functions in the imported package, a modified approach is necessary.

A2: Save the output of the private function in a support file. Then, load the support file when calling the support package's function that utilizes the private function.

The above is the detailed content of How to Share Test Utility Functions Between Packages?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn