News for hackers. Stuff that matters.
Re:Write tests. Not too many. Mostly integration by pjmlp on Friday October 27, 2017 @05:35AM (#15566891)
Is GUI code that 0.1%?

Because I am always keen to understand how to TDD GUI code and I don't mean the data model behind the pixels.

Re:Write tests. Not too many. Mostly integration by hacker_9 on Friday October 27, 2017 @05:42AM (#15566923)
Visual tests are more general, and are more akin to putting up barriers on either side of a bowling lane so the bowling ball stays within it's lane (with room to move about still). For example when using Angular, you write 'Page Objects' that have methods such as .getTitle(), .clickListItem(3) and so on, and can then write assertions to make sure the UI changes as expected by inspecting properties [1].

I usually find I build a general page object first ('this text is somewhere on the page'), then write the UI, then make the test more specific if I can after (but it's an art, as too specific and you risk creating too many false negatives when you make UI changes).

(Also as you are interacting with the UI, these would be known as integration tests.)

[1] https://semaphoreci.com/community/tutorials/using-page-objec...

Re:Write tests. Not too many. Mostly integration by pault on Friday October 27, 2017 @09:02AM (#15567869)
I don't think you can unit test GUIs, since by their nature all tests end up being integration tests. It's easy if you assign non-css (i.e. use a data-* attribute for identification instead of id or class since you want to keep those variable for stylesheet refactors) identifiers and just hard code the assumptions into the tests, like "when x is clicked y should be visible", or "when I enter 'foo' into the text field, the preview label should contain 'foo'". Ideally your assumptions about GUI functionality shouldn't change much throughout the lifetime of the project, and if you use static identifiers your tests should hold up during extensive refactoring.
Re:Write tests. Not too many. Mostly integration by pjmlp on Friday October 27, 2017 @09:37AM (#15568095)
That is my point of view, since my focus are mostly native GUIs.

Which is why it is my main question on TDD talks, that always use some library or CLI app as example.

Re:Write tests. Not too many. Mostly integration by maxxxxx on Friday October 27, 2017 @09:09AM (#15567909)
To a certain degree you can unit test GUIs with tools like Ranorex or Selenium. The question is how much setup you need to get the GUI on the screen with the right data.
Re:Write tests. Not too many. Mostly integration by pault on Friday October 27, 2017 @09:42AM (#15568141)
That isn't unit testing though, it's integration or e2e testing.
Re:Write tests. Not too many. Mostly integration by pjmlp on Friday October 27, 2017 @09:38AM (#15568103)
You can, but usually with lots of effort and cannot test UX and design requirements anyway, which is why I tend to make this question about full TDD based processes.
Re:Write tests. Not too many. Mostly integration by cjsuk on Friday October 27, 2017 @05:46AM (#15566941)
We use Ranorex for this: https://www.ranorex.com/
Re:Write tests. Not too many. Mostly integration by pjmlp on Friday October 27, 2017 @07:15AM (#15567314)
Interesting, thanks for the link.
Re:Write tests. Not too many. Mostly integration by TeMPOraL on Friday October 27, 2017 @06:13AM (#15567057)
I think so. I don't know how to unit test GUIs either.
Re:Write tests. Not too many. Mostly integration by oddlyaromatic on Friday October 27, 2017 @06:56AM (#15567212)
I saw an enjoyable talk recently about snapshot testing. I don't know too much about testing generally but it seems like it could be relevant: https://facebook.github.io/jest/docs/en/snapshot-testing.htm... is the general idea but it doesn't have to be confined to jest/react

Edit: Slides from the talk I saw: http://slides.com/bahmutov/snapshot-testing