The general rule we have is to test the model and the controls that dictate the changes to the UI, but the UI itself can't be tested with unit tests. ? Alternatively, you can try to take screen shots and try to do jpg comparisons (but I don't recommend it)
toggle quoted message
Show quoted text
On Mon, Nov 4, 2013 at 6:54 PM, Alan Baljeu <alanbaljeu@...> wrote:
?
I'm kind of new to WPF and trying to TDD an application that uses it. ?I'm a little frustrated that Microsoft's default program architecture still isn't TDD friendly. ?It creates an application project and adds a window and an app level resource dictionary, none of which can be tested because a test system requires a DLL it can load. ?But if I create a new DLL, it loses connection to the base resources because that's in the exe and not available in testing.
So the architecture seems wrong, and I don't know what's a more ideal way to proceed. ?Or, is there something I'm missing about testing UI code.
? Alan Baljeu
|
What's about MVVM and test the view model?
I would look for Caliburn.Micro
toggle quoted message
Show quoted text
On 04/11/2013, at 20:55, Avi Kessner < akessner@...> wrote:
?
The general rule we have is to test the model and the controls that dictate the changes to the UI, but the UI itself can't be tested with unit tests. ? Alternatively, you can try to take screen shots and try to do jpg comparisons (but I don't recommend it)
|
"The UI itself can't be tested with unit tests." ?Do you mean to suggest the UI itself won't be tested? ?You say controls should be tested, but how can you do this in the context of WPF which likes to put resources at the application level? ?Or maybe (I don't know this toolkit enough) the resources and such don't need testing because it's all style and not functional. ? Alan Baljeu On Monday, November 4, 2013 2:56:17 PM, Avi Kessner wrote:
?
The general rule we have is to test the model and the controls that dictate the changes to the UI, but the UI itself can't be tested with unit tests. ? Alternatively, you can try to take screen shots and try to do jpg comparisons (but I don't recommend it)
toggle quoted message
Show quoted text
On Mon, Nov 4, 2013 at 6:54 PM, Alan Baljeu <alanbaljeu@...> wrote:
?
I'm kind of new to WPF and trying to TDD an application that uses it. ?I'm a little frustrated that Microsoft's default program architecture still isn't TDD friendly. ?It creates an application project and adds a window and an app level resource dictionary, none of which can be tested because a test system requires a DLL it can load. ?But if I create a new DLL, it loses connection to the base resources because that's in the exe and not available in testing.
So the architecture seems wrong, and I don't know what's a more ideal way to proceed. ?Or, is there something I'm missing about testing UI code.
? Alan Baljeu
|
A benefit of Avi's approach is that it highly encourages a thin GUI that delegates as much as possible to directly testable code that reside in other DLLs, which we all know results in a better, more adaptable architecture.
Maybe, not being able to directly unit testing is ultimately not such a bad thing.
toggle quoted message
Show quoted text
On Mon, Nov 4, 2013 at 12:55 PM, Avi Kessner <akessner@...> wrote:
?
The general rule we have is to test the model and the controls that dictate the changes to the UI, but the UI itself can't be tested with unit tests. ? Alternatively, you can try to take screen shots and try to do jpg comparisons (but I don't recommend it)
|
So I guess nothing can go wrong! :-)
toggle quoted message
Show quoted text
On Mon, Nov 4, 2013 at 12:38 PM, Steven Gordon <sgordonphd@...> wrote:
?
A benefit of Avi's approach is that it highly encourages a thin GUI that delegates as much as possible to directly testable code that reside in other DLLs, which we all know results in a better, more adaptable architecture.
Maybe, not being able to directly unit testing is ultimately not such a bad thing.
|
Okay so I want to make a medium fancy list control on a page of a dialog, where each element of the list has a bunch of dropdowns arranged and styled nicely, and with contents of these dropdowns being intelligently assigned by the application logic.
What's your process for constructing this? 1. Create WPF application. 2. Create WPF user-control project. 3. ???
Alan Baljeu
On Monday, November 4, 2013 3:44:25 PM, Charlie Poole wrote:
?
So I guess nothing can go wrong! :-)
toggle quoted message
Show quoted text
On Mon, Nov 4, 2013 at 12:38 PM, Steven Gordon <sgordonphd@...> wrote:
?
A benefit of Avi's approach is that it highly encourages a thin GUI that delegates as much as possible to directly testable code that reside in other DLLs, which we all know results in a better, more adaptable architecture.
Maybe, not being able to directly unit testing is ultimately not such a bad thing.
|
It's software - of course, things can go wrong, even when there is 100% test coverage.
Tests cannot fully specify/verify the usability of GUI by humans, so manual testing of the GUI is necessary anyway. ?Just keep the GUI as thin as possible so that the logic and business rules are being specified/verified as well as possible,
toggle quoted message
Show quoted text
On Mon, Nov 4, 2013 at 1:44 PM, Charlie Poole <charliepoole@...> wrote:
?
So I guess nothing can go wrong! :-)
|
Hi Steve,
The fact that the user has to test the whole app anyway could be used as an excuse to eliminate all kinds of testing. In fact is has been used that way.
In Windows days, "Make your GUI thin" and separate it from other logic was what we told people as_a_starting_point. We then figured out how to test that thin layer, depending on the importance of whatever the application did and the risk associated with failure. GUIs for medical instruments, for example, do actually need to be tested, however thin they may be.
I'm pretty sure there are ways to be discovered for testing WPF. I'd be quite surprised if that way came out of Microsoft... it's more likely that this community will eventually figure it out. Architectures like MVVM and MVP help us move the untested stuff to tested. Some technologies tempt us to keep more in the untested side and WPF seems to be one of them. But so was Windows, and we still learned not to design apps the way the IDE generated them for us. I hope that will happen with WPF as wll.
Let's remember that "thin GUI" is a half-way measure. Ask yourself what can go wrong with your WPF and how you'll know when it does.
Charlie
toggle quoted message
Show quoted text
On Mon, Nov 4, 2013 at 1:07 PM, Steven Gordon <sgordonphd@...> wrote:
?
It's software - of course, things can go wrong, even when there is 100% test coverage.
Tests cannot fully specify/verify the usability of GUI by humans, so manual testing of the GUI is necessary anyway. ?Just keep the GUI as thin as possible so that the logic and business rules are being specified/verified as well as possible,
|
Well yes, I consider MVVM a given, and Caliburn.Micro looks like a good option. ?Now for testing a view I think I should want a fake ViewModel that just gives the view fixed data in order to see how well this data or that data are presented. ?But I'm not at all sure about this concept.
(At the moment I'm just drawing stuff in WPF just for gauging
looks. ?Not even a hint of logic is going anywhere. ?At some point I'll have to refactor and then introduce databinding etc.)
? Alan Baljeu On Monday, November 4, 2013 4:44:27 PM, David V¨ªlchez wrote:
?
What's about MVVM and test the view model?
I would look for Caliburn.Micro
toggle quoted message
Show quoted text
On 04/11/2013, at 20:55, Avi Kessner < akessner@...> wrote:
?
The general rule we have is to test the model and the controls that dictate the changes to the UI, but the UI itself can't be tested with unit tests. ? Alternatively, you can try to take screen shots and try to do jpg comparisons (but I don't recommend it)
|
From my (very little) experience with WPF, DataBinding is where the testing gets hard. Of course, you don't want to test that databinding works, since it's part of WPF, but there's always the risk that you not set it up correctly. That's a piece I don't really know how to test except by looking at the GUI.
Charlie
toggle quoted message
Show quoted text
On Mon, Nov 4, 2013 at 2:33 PM, Alan Baljeu <alanbaljeu@...> wrote:
?
Well yes, I consider MVVM a given, and Caliburn.Micro looks like a good option. ?Now for testing a view I think I should want a fake ViewModel that just gives the view fixed data in order to see how well this data or that data are presented. ?But I'm not at all sure about this concept.
(At the moment I'm just drawing stuff in WPF just for gauging
looks. ?Not even a hint of logic is going anywhere. ?At some point I'll have to refactor and then introduce databinding etc.)
? Alan Baljeu
On Monday, November 4, 2013 4:44:27 PM, David V¨ªlchez <dvilchez@...> wrote:
?
What's about MVVM and test the view model?
I would look for Caliburn.Micro
?
The general rule we have is to test the model and the controls that dictate the changes to the UI, but the UI itself can't be tested with unit tests. ? Alternatively, you can try to take screen shots and try to do jpg comparisons (but I don't recommend it)
brought to you by the letters A, V, and I and the number 47
On Mon, Nov 4, 2013 at 6:54 PM, Alan Baljeu <alanbaljeu@...> wrote:
?
I'm kind of new to WPF and trying to TDD an application that uses it. ?I'm a little frustrated that Microsoft's default program architecture still isn't TDD friendly. ?It creates an application project and adds a window and an app level resource dictionary, none of which can be tested because a test system requires a DLL it can load. ?But if I create a new DLL, it loses connection to the base resources because that's in the exe and not available in testing.
So the architecture seems wrong, and I don't know what's a more ideal way to proceed. ?Or, is there something I'm missing about testing UI code.
? Alan Baljeu
|
Just because you can't unit test the gui doesn't mean you avoid testing the gui.? You can't TDD yourself towards a good GUI.? But you can write acceptance tests after the fact.? When I was working on a windows phone app, what we did was create multiple projects.? One project was only the xaml code.? The other project was all our code which could be unit tested. (Ok, so technically it was 3 projects cause we had one with all the unit tests)
toggle quoted message
Show quoted text
?
From my (very little) experience with WPF, DataBinding is where the testing gets hard. Of course, you don't want to test that databinding works, since it's part of WPF, but there's always the risk that you not set it up correctly. That's a piece I don't really know how to test except by looking at the GUI.
Charlie
|
Alan, it sounds to me like you are on the right track.
toggle quoted message
Show quoted text
Just because you can't unit test the gui doesn't mean you avoid testing the gui.? You can't TDD yourself towards a good GUI.? But you can write acceptance tests after the fact.? When I was working on a windows phone app, what we did was create multiple projects.? One project was only the xaml code.? The other project was all our code which could be unit tested. (Ok, so technically it was 3 projects cause we had one with all the unit tests)
On 5 Nov 2013 03:30, "Charlie Poole" < charliepoole@...> wrote:
?
From my (very little) experience with WPF, DataBinding is where the testing gets hard. Of course, you don't want to test that databinding works, since it's part of WPF, but there's always the risk that you not set it up correctly. That's a piece I don't really know how to test except by looking at the GUI.
Charlie
|
In earlier times with Windows Forms I did something like this:
[Test] void Test() { ? var presenter = new Presenter(); ? var view = new View(presenter); ? view.Show(); ? presenter.model.x = 3; ? Assert.That(view.xcontrol.Value == 3); }
The details may be wrong but that was the concept.?
Alan Baljeu
toggle quoted message
Show quoted text
From: Charlie Poole To: testdrivendevelopment@... Sent: Monday, November 4, 2013 8:30:37 PM Subject: Re: [TDD] Test Driving WPF
?
From my (very little) experience with WPF, DataBinding is where the testing gets hard. Of course, you don't want to test that databinding works, since it's part of WPF, but there's always the risk that you not set it up correctly. That's a piece I don't really know how to test except by looking at the GUI.
Charlie
|
How do you write acceptance tests? ? Alan Baljeu
toggle quoted message
Show quoted text
From: Avi Kessner To: testdrivendevelopment@... Sent: Tuesday, November 5, 2013 2:06:11 AM Subject: Re: [TDD] Test Driving WPF
?
Just because you can't unit test the gui doesn't mean you avoid testing the gui.? You can't TDD yourself towards a good GUI.? But you can write acceptance tests after the fact.? When I was working on a windows phone app, what we did was create multiple projects.? One project was only the xaml code.? The other project was all our code which could be unit tested. (Ok, so technically it was 3 projects cause we had one with all the unit tests)
On 5 Nov 2013 03:30, "Charlie Poole" < charliepoole@...> wrote:
?
From my (very little) experience with WPF, DataBinding is where the testing gets hard. Of course, you don't want to test that databinding works, since it's part of WPF, but there's always the risk that you not set it up correctly. That's a piece I don't really know how to test except by looking at the GUI.
Charlie
|
Having difficulty visualizing what you're trying to build.
Here's whats worked for me... - Use MVVM because otherwise you'd be fighting WPF most of the time.. Windows Forms and WPF are different beasts .. so mapping old experience mostly doesn't work.
- ViewModel: Your view model should hold the state for the view. This means that you can trigger it via changing "Properties" or executing 'Commands' and inspect the results. (State based testing)
- Model: You can verify whether the view model invokes the right methods on the backing model - Use state/interaction based style as you find comfortable. You can usually test the Model independently because it generally has no dependencies on either the VM or the View.
- View: I'm mostly okay with not testing this at all because usually it should just contain "Bindings". Frameworks like Caliburn use convention to auto-magically bind view controls to VM properties/commands. Minimize any code in the code-behind
- Finally you'll still have tests where you need to test interaction between multiple viewmodels or you just had to write some code in the code-behind (because the MVVM way was too hard - e.g. testing default focus) - I've had some amount of success with white (not called teststack.white) which drives GUIs on Windows.?
Special mentions: Bypass the dispatcher - this is a 'golden rule' of windows GUI - a UI element should only be accessed from the thread on which it was created. This means that once you're done doing the heavy lifting on a worker thread, you need to channel the UI updation back on to the main/UI thread. You usually do this by saying UIControl.Dispatcher.Invoke() / BeginInvoke()
In your tests, there won't be a UI Thread - so you need to fake this and make it just a Sync Invoke() HTH Gishu
PS: It can be done :)
|
At present, I'm simply trying to build an understanding of good TDD with WPF. ?I'd love to find a tutorial for Caliburn.Micro that demonstrates test-driving. ?I think the prerequisite for this is to push these classes into class library projects, and I'm not seeing that out there.
(Eventually I want to make a multipage form, but just anything to get me
understanding is good now. ?I have a vague sense that Caliburn represents a way of thinking I'm not accustomed to. ?Reading more now.) ?
Alan Baljeu
toggle quoted message
Show quoted text
From: Gishu Pillai To: testdrivendevelopment@... Sent: Tuesday, November 5, 2013 10:16:02 AM Subject: Re: [TDD] Test Driving WPF
?
Having difficulty visualizing what you're trying to build.
Here's whats worked for me... - Use MVVM because otherwise you'd be fighting WPF most of the time.. Windows Forms and WPF are different beasts .. so mapping old experience mostly doesn't work.
- ViewModel: Your view model should hold the state for the view. This means that you can trigger it via changing "Properties" or executing 'Commands' and inspect the results. (State based testing)
- Model: You can verify whether the view model invokes the right methods on the backing model - Use state/interaction based style as you find comfortable. You can usually test the Model independently because it generally has no dependencies on either the VM or the View.
- View: I'm mostly okay with not testing this at all because usually it should just contain "Bindings". Frameworks like Caliburn use convention to auto-magically bind view controls to VM properties/commands. Minimize any code in the code-behind
- Finally you'll still have tests where you need to test interaction between multiple viewmodels or you just had to write some code in the code-behind (because the MVVM way was too hard - e.g. testing default focus) - I've had some amount of success with white (not called teststack.white) which drives GUIs on Windows.?
Special mentions: Bypass the dispatcher - this is a 'golden rule' of windows GUI - a UI element should only be accessed from the thread on which it was created. This means that once you're done doing the heavy lifting on a worker thread, you need to channel the UI updation back on to the main/UI thread. You usually do this by saying UIControl.Dispatcher.Invoke() / BeginInvoke()
In your tests, there won't be a UI Thread - so you need to fake this and make it just a Sync Invoke() HTH Gishu
PS: It can be done :)
|
Yup, me too! More recently, I've done the same using a mock view.
Do you know how to do the same / similar with WPF? Charlie
toggle quoted message
Show quoted text
?
In earlier times with Windows Forms I did something like this:
[Test]
void Test()
{ ? var presenter = new Presenter();
? var view = new View(presenter);
? view.Show();
? presenter.model.x = 3; ? Assert.That(view.xcontrol.Value == 3);
}
The details may be wrong but that was the concept.?
Alan Baljeu
?
From my (very little) experience with WPF, DataBinding is where the testing gets hard. Of course, you don't want to test that databinding works, since it's part of WPF, but there's always the risk that you not set it up correctly. That's a piece I don't really know how to test except by looking at the GUI.
Charlie
On Mon, Nov 4, 2013 at 2:33 PM, Alan Baljeu <alanbaljeu@...> wrote:
?
Well yes, I consider MVVM a given, and Caliburn.Micro looks like a good option. ?Now for testing a view I think I should want a fake ViewModel that just gives the view fixed data in order to see how well this data or that data are presented. ?But I'm not at all sure about this concept.
(At the moment I'm just drawing stuff in WPF just for gauging
looks. ?Not even a hint of logic is going anywhere. ?At some point I'll have to refactor and then introduce databinding etc.)
? Alan Baljeu
On Monday, November 4, 2013 4:44:27 PM, David V¨ªlchez <dvilchez@...> wrote:
?
What's about MVVM and test the view model?
I would look for Caliburn.Micro
?
The general rule we have is to test the model and the controls that dictate the changes to the UI, but the UI itself can't be tested with unit tests. ? Alternatively, you can try to take screen shots and try to do jpg comparisons (but I don't recommend it)
brought to you by the letters A, V, and I and the number 47
On Mon, Nov 4, 2013 at 6:54 PM, Alan Baljeu <alanbaljeu@...> wrote:
?
I'm kind of new to WPF and trying to TDD an application that uses it. ?I'm a little frustrated that Microsoft's default program architecture still isn't TDD friendly. ?It creates an application project and adds a window and an app level resource dictionary, none of which can be tested because a test system requires a DLL it can load. ?But if I create a new DLL, it loses connection to the base resources because that's in the exe and not available in testing.
So the architecture seems wrong, and I don't know what's a more ideal way to proceed. ?Or, is there something I'm missing about testing UI code.
? Alan Baljeu
|
Nice summary. I like "mapping old experience doesn't work" ... except it's the only kind I have. :-)
Charlie
toggle quoted message
Show quoted text
On Tue, Nov 5, 2013 at 7:16 AM, Gishu Pillai <gishu.pillai@...> wrote:
?
Having difficulty visualizing what you're trying to build.
Here's whats worked for me... - Use MVVM because otherwise you'd be fighting WPF most of the time.. Windows Forms and WPF are different beasts .. so mapping old experience mostly doesn't work.
- ViewModel: Your view model should hold the state for the view. This means that you can trigger it via changing "Properties" or executing 'Commands' and inspect the results. (State based testing)
- Model: You can verify whether the view model invokes the right methods on the backing model - Use state/interaction based style as you find comfortable. You can usually test the Model independently because it generally has no dependencies on either the VM or the View.
- View: I'm mostly okay with not testing this at all because usually it should just contain "Bindings". Frameworks like Caliburn use convention to auto-magically bind view controls to VM properties/commands. Minimize any code in the code-behind
- Finally you'll still have tests where you need to test interaction between multiple viewmodels or you just had to write some code in the code-behind (because the MVVM way was too hard - e.g. testing default focus) - I've had some amount of success with white (not called teststack.white) which drives GUIs on Windows.?
Special mentions: Bypass the dispatcher - this is a 'golden rule' of windows GUI - a UI element should only be accessed from the thread on which it was created. This means that once you're done doing the heavy lifting on a worker thread, you need to channel the UI updation back on to the main/UI thread. You usually do this by saying UIControl.Dispatcher.Invoke() / BeginInvoke()
In your tests, there won't be a UI Thread - so you need to fake this and make it just a Sync Invoke() HTH Gishu
PS: It can be done :)
|
Not a clue. ?I'm presently trying to find a tutorial on TDD with Caliburn.Micro. ? Alan Baljeu
From: Charlie Poole To: testdrivendevelopment@... Sent: Tuesday, November 5, 2013 2:47:55 PM Subject: Re: [TDD] Test Driving WPF
?
Yup, me too! More recently, I've done the same using a mock view.
Do you know how to do the same / similar with WPF? Charlie
toggle quoted message
Show quoted text
?
In earlier times with Windows Forms I did something like this:
[Test]
void Test()
{ ? var presenter = new Presenter();
? var view = new View(presenter);
? view.Show();
? presenter.model.x = 3; ? Assert.That(view.xcontrol.Value == 3);
}
The details may be wrong but that was the concept.?
Alan Baljeu
?
From my (very little) experience with WPF, DataBinding is where the testing gets hard. Of course, you don't want to test that databinding works, since it's part of WPF, but there's always the risk that you not set it up correctly. That's a piece I don't really know how to test except by looking at the GUI.
Charlie
On Mon, Nov 4, 2013 at 2:33 PM, Alan Baljeu <alanbaljeu@...> wrote:
?
Well yes, I consider MVVM a given, and Caliburn.Micro looks like a good option. ?Now for testing a view I think I should want a fake ViewModel that just gives the view fixed data in order to see how well this data or that data are presented. ?But I'm not at all sure about this concept.
(At the moment I'm just drawing stuff in WPF just for gauging
looks. ?Not even a hint of logic is going anywhere. ?At some point I'll have to refactor and then introduce databinding etc.)
? Alan Baljeu
On Monday, November 4, 2013 4:44:27 PM, David V¨ªlchez <dvilchez@...> wrote:
?
What's about MVVM and test the view model?
I would look for Caliburn.Micro
?
The general rule we have is to test the model and the controls that dictate the changes to the UI, but the UI itself can't be tested with unit tests. ? Alternatively, you can try to take screen shots and try to do jpg comparisons (but I don't recommend it)
brought to you by the letters A, V, and I and the number 47
On Mon, Nov 4, 2013 at 6:54 PM, Alan Baljeu <alanbaljeu@...> wrote:
?
I'm kind of new to WPF and trying to TDD an application that uses it. ?I'm a little frustrated that Microsoft's default program architecture still isn't TDD friendly. ?It creates an application project and adds a window and an app level resource dictionary, none of which can be tested because a test system requires a DLL it can load. ?But if I create a new DLL, it loses connection to the base resources because that's in the exe and not available in testing.
So the architecture seems wrong, and I don't know what's a more ideal way to proceed. ?Or, is there something I'm missing about testing UI code.
? Alan Baljeu
|
I have been searching a lot for some guidance and am coming up short. ?Okay, maybe an easier question:
I believe that to unit test, you need to have code in a class library project rather than an application project. ?I also read that somebody suggests separating V and VM into two projects. ?Do
you think this is right? ?Can anybody point me to instructions on doing this? ? Alan Baljeu
toggle quoted message
Show quoted text
From: Alan Baljeu To: "testdrivendevelopment@..." Sent: Tuesday, November 5, 2013 3:01:39 PM Subject: Re: [TDD] Test Driving WPF
?
Not a clue. ?I'm presently trying to find a tutorial on TDD with Caliburn.Micro. ? Alan Baljeu
From: Charlie Poole To: testdrivendevelopment@... Sent: Tuesday, November 5, 2013 2:47:55 PM Subject: Re: [TDD] Test Driving WPF
?
Yup, me too! More recently, I've done the same using a mock view.
Do you know how to do the same / similar with WPF? Charlie
|