-
Notifications
You must be signed in to change notification settings - Fork 462
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
Add unit test project to solution #299
Comments
Similar to my comments in #300 - would this be optional as it currently is when creating a new blank project? |
why not just allow someone to opt in as a system level and make the whole project straight up testable. With that said, I can see how to do UI testing, but to do stub out a proper unit test without any business logic? feels odd as not sure how much would be testable |
My thinking was that by making this a "feature" it becomes optional. Even if we only added a single test which included |
Perhaps add some commented examples of some types of tests that you can perform just to show how to best write tests based on selected conditions. The conditions for writing tests differ depending on the chosen framework (Code behind, MVVM Basic, MVVM light, PRISM), how Dependency injection is performed, chosen unit test and mock framework, etc. |
Once we get to FCU as a minimum SDK and split out potentially X-Plat functionality this could be 3 options:
|
moving back to backlog as timeline for major restructuring is now undetermined |
@mrlacey, will this be possible to be done for 3.0? |
Just like #300 this is blocked by the NuGet issue that is preventing us generating multi-project solutions. Not necessary for 3.0 so moving to 3.1 |
Thinking about what to name the projects added to the solution and need them to be unique (so we can add them all to a solution--even if only in testing) but meaningful. I'm thinking:
Using the common prefix of I'd be happy to drop the ".Unit" element from the compound names above if people don't think it adds value. Note. The generated UI Test project is called speak up if you have objections or alternate suggestions. |
My thought for "Unit" tests is to just include a simple test that checks something is returned by the sample data service: var actual = SampleDataService.GetSampleModelDataAsync();
Assert.IsNotNull(actual);
Assert.AreNotEqual(0, actual.Count); This would mean adding a page that uses the SampleDataService or making For the UWP test project, include a test like this so it's enough to show access to the contents of a ViewModel. For the CodeBehind version it could test the property on the var sut = new ViewModels.SettingsViewModel();
var actualDescription = sut.VersionDescription;
Assert.IsFalse(string.IsNullOrWhiteSpace(actualDescription)); Both these suggestions require adding a dependency to other pages. While including unneeded pages isn't great, if we want to include example tests that actually test something useful, I don't see another option as there isn't anything appropriate to test in the base generated project. Thoughts? Suggestions? |
@mrlacey for the naming of test projects I'd drop the Unit part and add the full name of the tested project, like this: • {App}.Core.Tests.MSTest (would reference {App}.Core) Regarding the dependencies: |
Latest thinking:
I also like the idea of being able to have the generated code link to some documentation that would help anyone getting started with unit testing but it's such a big topic, I wouldn't want to try and write something myself. I can't even find any suitable docs to link to. :'( |
SampleDataService only exposes anything public when there are other items that use it. I want to avoid changing this or deal with exposing internals as that's often considered an anti-pattern. Adding a separate page just to demonstrate how to test something also feels wrong. Whether it's a new or existing one I just don't think we should do it. We've decided against including things just for the sake of demonstration in the past. (The potential exception being deep linking but what we added made the feature complete. It will still be possible to use and run the tests in the test project without including dependencies on parts of the app.) If we had a separate selectable item which was "demo test content" then maybe I'd be ok with that but including such a thing would set a dangerous precedent for other templates and requests for support and documentation. Will review all pages and features for possible test integration. |
Think we should also have versions of the app tests for each framework too. • {App}.Core.Tests.MSTest (would reference {App}.Core) in addition to
This means there's the potential to add seven additional projects to a generated solution. We'd do this in tests, but the most that makes reasonable sense for someone to include would be three (one for the app, one for the core lib, and one for the UI-with WAD.) I'll be keen to see the telementry on what people do actually add though. |
I'd thought about making test frameworks mutually exclusive but I don't see any real benefit to it. There are other features that have been discussed separately where a genuine mutual exclusion of options would be necessary but as we don't need that yet, lets focus on providing end user (developer) functionality with the infrastructure we already have. With regard composition, I haven't looked at it in detail but had a few ideas.
|
Adding example tests based on other selected items What If adding a test feature and select a page that adds content we can add an example test for, we should add such a test. Example. How By extending Doing so means the ability to have a composition filter like this:
This includes the composition template if using one of the defined frameworks, have included an item with the identity of "wts.Feat.UnitTests.Core.MSTest" and have also added a page with the Identity of "wts.Page.Chart" or "wts.Page.Chart.CodeBehind". Just including one of either the chart page or the test library feature and the generator does not attempt to add the extra test. The order of selected items doesn't matter. You can add the page, then the feature, or the other way round. If this filter was used with a template identity that allows multiple instances there is the possibility that this could break things as it might try and add duplicate items. It shouldn't have an issue for the functionality I'm adding here. I don't think it's something we should prevent as it might be desirable for other scenarios. Our template tests would catch anything that caused a breaking build, but this is potentially powerful and will need a note in the documentation. This would work with Right-click>Add but with a slight difference Attempting to conditionally add the test when doing a right-click addition would be complicated and error-prone. I only need @sibille thoughts on this approach? |
Looks correct to me! I was initially thinking about approaching this differently: Composition filter would look like this: I think both approaches are valid, we should look into advantages for each one. |
Ok. Two issues to resolve
Filtering Adding a specialized Managing shared code To add all the sample data tests via the different options is going to require 36 new composition templates. (I think--I've so far only made 7 of them to explore options.) Alternatives to reduce the number of composition files being added here:
These options were previously ruled out as being undesirable. As these (36) composition templates are all very small, the chances of needing to change anything in them (one of the main reasons for reducing duplication) is also very small. |
Also updates VB style checks to run on all projects in the solution & fix issues they found Also added build tests to run all the tests after building with all pages and features For microsoft#299
Adding tests for code in the app projects is currently blocked by microsoft/microsoft-ui-xaml#230 |
The ability to use NUnit to create tests against the app cannot be added at this time as NUnit does not support it, yet. This and #300 means we'll only be adding 6 new features relating to Testing |
I'm reviewing what's appropriate to add to the App tests project based on other selected items. There is very little that's easy or appropriate to test in the View Models that are produced by default. For example, adding a Camera Page/ViewModel would give you this:
It adds a test to the test project. |
Because some Prism ViewModels require the injection of dependencies, I'm using |
Waiting for #2527 and then will submit PR |
verified in |
Add a feature to add a unit test project to the solution. This should include a reference to the app project.
Need to consider what, if any, test(s) to include by default.
The text was updated successfully, but these errors were encountered: