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

Please also add .net as TargetFramework (makes it possible to unit test my maui project) #102

Open
3sRykaert opened this issue Feb 15, 2024 · 13 comments

Comments

@3sRykaert
Copy link

3sRykaert commented Feb 15, 2024

In the following file:
https://github.com/dotMorten/MauiEx/blob/main/MauiEx/MauiEx.csproj

Please change:
<TargetFrameworks>net7.0-android;net7.0-ios;net7.0-maccatalyst</TargetFrameworks>
To:
<TargetFrameworks>net7.0;net7.0-android;net7.0-ios;net7.0-maccatalyst</TargetFrameworks>

That way a unittest project can also run against a maui project that uses this package.

@dotMorten
Copy link
Owner

There is no implementation for net7.0 though - are you using ui in your unit tests?

@3sRykaert
Copy link
Author

An implementation for net7.0 is not needed imho.
I need to unittest certain (businesslogic) in my maui app that aren't ui related.
Cause the "standard net7.0" is missing in this project, my unittest fail to build.
All other packages I used (f.e. https://github.com/Alex-Dobrynin/Controls.UserDialogs.Maui/blob/master/Controls.UserDialogs.Maui/Controls.UserDialogs.Maui.csproj) also have "the standard .net framework" as a TargetFramework.

So to resume: you won't need to change anything beside adjusting the csproj file. No concrete implementation is needed.

@dotMorten
Copy link
Owner

No concrete implementation is needed.

That's not quite true. There needs to be code to handle and provide developers with feedback that platforms aren't supported like if they try and run it on tizen or macos.
Why aren't you just making your unit tests target the platforms that are actually supported? Maui needs a platform specific target to actually function

@3sRykaert
Copy link
Author

Why aren't you just making your unit tests target the platforms that are actually supported?

UnitTest won't work in a android project (they don't run).
See also: https://www.youtube.com/watch?v=C9vIDLQwc7M and https://github.com/jfversluis/MauixUnitTestSample

There needs to be code to handle and provide developers with feedback that platforms aren't supported like if they try and run it on tizen or macos.

I don't think that's needed, since you don't target them by adding net7.0

@dotMorten
Copy link
Owner

dotMorten commented Feb 17, 2024

They will work in a Windows project or use a test runner to run on actual devices .
The net7 lib is used if there's no platform match so it is needed

@3sRykaert
Copy link
Author

3sRykaert commented Feb 17, 2024

They will work in a Windows project or use a test runner to run on actual devices .

I use xunit to run my unit-tests, why would I want to run those on a device? The only thing that's blocking me, is that this package also needs to target the "standard framework". When you look at for example: https://github.com/Alex-Dobrynin/Controls.UserDialogs.Maui/tree/master this doesn't need any specific implementation when using the default framework (= net8.0 for this example). So I'm pretty sure, that besides adding it in the csproj file, no changes are required.

The net7 lib is used if there's no platform match so it is needed

I don't understand what you're saying here, to be honest. Can you elaborate please?

@dotMorten
Copy link
Owner

dotMorten commented Feb 17, 2024

I don't understand what you're saying here

If you use my library in a Tizen app it will use the net7.0 library since there isn't a platform match and it won't work.

I'm not saying it isn't possible, but it isn't true that there are no code changes needed. At a minimum there needs to be platform support attributes, so the tizen developer at least gets build warnings. RIght now I'm avoiding all that by clearly stating which platforms I support.

@dotMorten
Copy link
Owner

why would I want to run those on a device

Why wouldn't you? Your users will be running on a device. You'd be surprised about the number of platform differences. I daily run all my unit tests on windows, ios, catalyst and android devices.
Is the real reason here that your view models are not separate from your view code, so you can't build those without bringing in all the view controls?

@3sRykaert
Copy link
Author

3sRykaert commented Feb 18, 2024

Is the real reason here that your view models are not separate from your view code, so you can't build those without bringing in all the view controls?

That's correct indeed. Indeed splitting them would also solve this. But any guide/faq/example for Maui I have seen so far, is build that way. Don't get me wrong, I truly have respect for the work you are doing and the package itself, but this is really blocking me.
Every other package that I use for gui stuff, also have the standard network as build target.

If you use my library in a Tizen app it will use the net7.0 library since there isn't a platform match and it won't work.

I don't think that's true; cause that's kind of like the issue I'm currently facing: a (test) project in "standard .net 7.0" which can't build cause of a linked package doesn't target it.
I guess this will be same, if I have a tizen project, with a package that doesn't target Tizen.
To target Tizen, you need to explicitly add it, no?
<!-- Uncomment to also build the tizen app. You will need to install tizen by following this: https://github.com/Samsung/Tizen.NET -->
<!-- <TargetFrameworks>$(TargetFrameworks);net8.0-tizen</TargetFrameworks> -->

Maybe, in worst case, you can do something like:
#if TIZEN
#error NOT SUPPORTED
#endif

@dotMorten
Copy link
Owner

Again I'm not saying I won't address this - just that it's a little bit more work than you think if you want to do it right and I'm pretty backed up with work for the next month or so. It is open source so you can use a custom local build until I get to it.

#if TIZEN and throw won't work. That would require I also target tizen and there are still more platforms like macos which from the sound of it is what you're running on. It would also prevent anyone from adding a custom tizen handler

@veringm
Copy link

veringm commented May 6, 2024

I'm very happy with your lib @dotMorten, but I'm facing the same issue as @3sRykaert. I have non-platform specific unit-test on services and view-models. For this reason, I target my own app for .net-8.0.

I might be able to make my client support you, @dotMorten what would I take to make you prioritize adding .net support?

@dotMorten
Copy link
Owner

Can you help me understand how you’re using this control in your services and view models? That sounds counter to the mvvm patterns

@veringm
Copy link

veringm commented May 6, 2024

Hi @dotMorten thx for your reply. I'm using your lib on a single page in a xaml-file and a code-behind file (not really mvvm in this case), but no where else. I do not make any test of this specific page. In fact I only make test of services and view-models, I do not make ui-test. The thing is, that the code is not specific to either android nor ios (my two target platforms for the users), so targeting .net for test seems like the right choice.

Back in the Xamarin.Forms days, I had a shared .net project, that android and ios just depended on. And a unit test-suite for the shared .net project (no test for the android and ios projects).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants