Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ActiveDirectoryDsc: Add stubs to be used with unit tests #245

Closed
johlju opened this issue Mar 12, 2019 · 3 comments · Fixed by #483
Closed

ActiveDirectoryDsc: Add stubs to be used with unit tests #245

johlju opened this issue Mar 12, 2019 · 3 comments · Fixed by #483
Labels
tests The issue or pull request is about tests only.

Comments

@johlju
Copy link
Member

johlju commented Mar 12, 2019

I think we need to add stubs to use in the unit tests, similar that was done in SqlServerDsc https://github.com/PowerShell/SqlServerDsc/tree/dev/Tests/Unit/Stubs.

For example there is no need to add helper functions to support mocking (which lowers the code coverage also). An example is here, a function that was added because we are missing stubs.

https://github.com/PowerShell/xActiveDirectory/blob/e4817bf4fa710c79455816a56a20665bd0dd1162/DSCResources/MSFT_xADReplicationSiteLink/MSFT_xADReplicationSiteLink.psm1#L300-L326

@johlju johlju added help wanted The issue is up for grabs for anyone in the community. tests The issue or pull request is about tests only. labels Mar 12, 2019
@johlju
Copy link
Member Author

johlju commented Jun 22, 2019

I tried to use @indented-automation's module https://github.com/indented-automation/Indented.StubCommand to generate the full stubs, but ran into a couple of issues (that I could not solve on my own). See the README.md my branch here https://github.com/johlju/xActiveDirectory/tree/add-stubs/Tests/Unit/Stubs which also links to the issues.

Feel free to continue this work and make it better. 😄

@johlju
Copy link
Member Author

johlju commented Jul 17, 2019

There seems to be a problem with the build worker loading in the assemblies so that classed are present, that means that our stub classes (for example Microsoft.ActiveDirectory.Management.cs) cannot be loaded. This can result in different results between running unit test locally and running them on the build worker.

I think this can have something to do with the meta tests running (common tests in the test framework) that imports this module for some reason.
I option would be to split up meta test and unit tests in different jobs, so that we can better control what is loaded and not. I will add this to a separate issue.

@johlju johlju changed the title xActiveDirectory: Add stubs to be used with unit tests ActiveDirectoryDsc: Add stubs to be used with unit tests Jul 28, 2019
@johlju
Copy link
Member Author

johlju commented Aug 8, 2019

I suggest we simplify the stubs of the AD cmdlets. Parameters in the cmlets are today referencing various ActiveDirectory classes which also demands that we need to have stubs for those classes. I suggest that we just change all the stub cmdlet parameters to use [System.Object]. We use these in unit tests, so we are really just intrested if the cmdlet are called using a specific parameter, and maybe check the value passed. We are no interested to test an actual scenario, that is what the integration tests are for. 🤔 We still need stub classes for resource that reference the types directly in code.

I think this would lower the bar for new contributors to write tests. Using [System.Object] in the cmdlet parameters have been done for the SqlServerDsc module and it have worked flawless.

@johlju johlju added in progress The issue is being actively worked on by someone. and removed help wanted The issue is up for grabs for anyone in the community. labels Aug 13, 2019
johlju added a commit that referenced this issue Aug 21, 2019
- Changes to ActiveDirectoryDsc
  - Added new stubs for the cmdlets and classes to be used with unit tests.
    The new stubs are based on the modules ActiveDirectory and ADDSDeployment
    in Windows Server 2019. The stubs are generated using the PowerShell
    module *Indented.StubCommand*. Instructions how to generate stubs
    (for example for a new operating system) has been added to the README.md
    in the `Tests/Unit/Stubs` folder ([issue #245](#245)).
  - Update all unit tests removing all local stub functions in favor of
    the new stub modules.
  - Changes to ActiveDirectoryDsc.Common.
    - Updated the function `Test-ADReplicationSite` to make the parameter
      `Credential` mandatory.
@johlju johlju removed the in progress The issue is being actively worked on by someone. label Aug 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tests The issue or pull request is about tests only.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant