Skip to content

TestWriter class

Ershad Raoufi- ارشاد رئوفی edited this page Mar 20, 2023 · 2 revisions

This code defines a static class TestWriter in the TestCreator.Core namespace that provides methods to generate unit test files for enums in a given set of assemblies. The class provides four overloaded methods with different parameters to support various use cases.

The first method CreateUnitTestFilesFromAssemblies takes in the path where the test files will be created, a list of assembly names in selectedAssembly, an assertType and a unitTestFrameworkType to be used for the generated test files. It also provides a overWriteTests flag to overwrite existing test files if they exist. This method validates the input parameters and delegates the actual creation of the test files to a DefaultUnitTestWriter instance.

The second method CreateUnitTestFilesFromAssemblies takes the same input parameters as the first method, but instead of assertType and unitTestFrameworkType, it takes a BaseUnitTestWriter instance. This method validates the input parameters and delegates the actual creation of the test files to the passed BaseUnitTestWriter instance.

The third and fourth methods are similar to the first two methods, but instead of a list of assembly names, they take a Dictionary of assembly names and their corresponding paths where the test files will be created.

Overall, this class provides a simple API to generate unit test files for enums in a set of assemblies. The generated test files use the selected assertType and unitTestFrameworkType. The actual creation of test files is delegated to DefaultUnitTestWriter or a passed BaseUnitTestWriter instance.

Here is a more detailed explanation of each of the methods: CreateUnitTestFilesFromAssemblies(string path, string[] selectedAssembly, AssertType assertType = AssertType.Assert, UnitTestFrameworkType unitTestFrameworkType = UnitTestFrameworkType.XUnit, bool overWriteTests = false) This method takes in several input parameters, including a path to where the unit tests will be created, an array of assembly names to search for enums, an optional AssertType parameter, an optional UnitTestFrameworkType parameter, and an optional boolean parameter to overwrite existing tests.

The method first performs several argument validation checks before calling an instance of the DefaultUnitTestWriter class to write the unit tests for the specified enums.

CreateUnitTestFilesFromAssemblies(string path, string[] selectedAssembly, BaseUnitTestWriter baseUnitTestWriter, bool overWriteTests = false) This method takes in several input parameters, including a path to where the unit tests will be created, an array of assembly names to search for enums, an instance of the BaseUnitTestWriter class, and an optional boolean parameter to overwrite existing tests.

The method first performs several argument validation checks before calling the specified BaseUnitTestWriter instance to write the unit tests for the specified enums.

CreateUnitTestFilesFromAssemblies(IDictionary<string, string> selectedAssembly, AssertType assertType = AssertType.Assert, UnitTestFrameworkType unitTestFrameworkType = UnitTestFrameworkType.XUnit, bool overWriteTests = false) This method takes in several input parameters, including a dictionary of assembly names and their corresponding paths to search for enums, an optional AssertType parameter, an optional UnitTestFrameworkType parameter, and an optional boolean parameter to overwrite existing tests.

The method iterates over the dictionary of assembly names and paths and calls the CreateUnitTestFilesFromAssemblies method with the corresponding parameters for each assembly.

CreateUnitTestFilesFromAssemblies(IDictionary<string, string> selectedAssembly, BaseUnitTestWriter baseUnitTestWriter, bool overWriteTests = false) This method takes in several input parameters, including a dictionary of assembly names and their corresponding paths to search for enums, an instance of the BaseUnitTestWriter class, and an optional boolean parameter to overwrite existing tests.

The method iterates over the dictionary of assembly names and paths and calls the CreateUnitTestFilesFromAssemblies method with the corresponding parameters for each assembly, using the specified BaseUnitTestWriter instance.

Clone this wiki locally