Speedway

Module talk:ScribuntoUnit: Difference between revisions

Content deleted Content added
No edit summary
Line 13: Line 13:
:That sounded like a good idea to me, and it will be useful for [[Module:Documentation]] which I'm working on now, so I went ahead and added an [[Module:ScribuntoUnit#assertContains|assertContains]] method. Take a look and let me know if you have any suggestions for how it could be improved. — '''''[[User:Mr. Stradivarius|<span style="color: #194D00; font-family: Palatino, Times, serif">Mr. Stradivarius</span>]]''''' <sup>[[User talk:Mr. Stradivarius|♪ talk ♪]]</sup> 16:32, 2 January 2014 (UTC)
:That sounded like a good idea to me, and it will be useful for [[Module:Documentation]] which I'm working on now, so I went ahead and added an [[Module:ScribuntoUnit#assertContains|assertContains]] method. Take a look and let me know if you have any suggestions for how it could be improved. — '''''[[User:Mr. Stradivarius|<span style="color: #194D00; font-family: Palatino, Times, serif">Mr. Stradivarius</span>]]''''' <sup>[[User talk:Mr. Stradivarius|♪ talk ♪]]</sup> 16:32, 2 January 2014 (UTC)
:: It looks great, thank you :) Do you have a page where you check the assertions work correctly and that their diagnostic messages look good? I did not find [[Module:ScribuntoUnit/testcases]]. --[[User:Derbeth|Derbeth]] [[User talk:Derbeth|<sup>talk</sup>]] 20:01, 2 January 2014 (UTC)
:: It looks great, thank you :) Do you have a page where you check the assertions work correctly and that their diagnostic messages look good? I did not find [[Module:ScribuntoUnit/testcases]]. --[[User:Derbeth|Derbeth]] [[User talk:Derbeth|<sup>talk</sup>]] 20:01, 2 January 2014 (UTC)
::: Great. But perhaps we should name it <code>assertStringContains</code> in case we later implement a method that checks if a table contains a given table key? And yes, we should have tests for the assertions as well. I'm not really sure how to write good tests for a testing module, but I started experimenting on [[Module:ScribuntoUnit/testcases]]. – ''[[User:Danmichaelo|Danmichaelo]] ([[User talk:Danmichaelo|talk]])'' 08:42, 3 January 2014 (UTC)

Revision as of 08:42, 3 January 2014

Test a string contains expected text

I think there is a need for an assertion that checks that a string contains expected text. Motivation is as follows: you should test behaviour, not test methods and each test method should only test one thing. Suppose you have a complicated module (pl:Moduł:Koordynaty) that 1) adds a formatted link 2) prints out a formatted text 3) adds the page to a calculated category (and maybe will do other things in the future we cannot predict, and we don't want people adding one new feature to fix assertions for all other features just because module output has grown). To write a proper unit test, you should write 3 separate test methods, each checking only one functionality and no other, so that when only 1 of the functionalities is broken, exactly 1 test fails and no other. To achieve this, you need a method like

assertThat(coordinates.invoke("53 45", "23 45"), containsString("geohack/53.45W_23.45E/type:city"))

where you check a part of the module output and don't care about the rest. Also, there are modules that create multi-line outputs. Tests need to be readable and check only what is relevant. Therefore an "contains string" assertion would be handy.

In JUnit, you can deal with the lack of "assertContains" by using assertTrue() with a custom message displayed when the assertion fails. Here, there is no way to pass the failure message. Hence, assertTrue from ScribuntoUnit is not suitable for implementing "contains string" assertions, because there will be no meaningful error message.

I suggest either adding a new method "assertContains" or extending "assertTrue" with a failure message - or perhaps performing both. --Derbeth talk 21:40, 1 January 2014 (UTC)[reply]

That sounded like a good idea to me, and it will be useful for Module:Documentation which I'm working on now, so I went ahead and added an assertContains method. Take a look and let me know if you have any suggestions for how it could be improved. — Mr. Stradivarius ♪ talk ♪ 16:32, 2 January 2014 (UTC)[reply]
It looks great, thank you :) Do you have a page where you check the assertions work correctly and that their diagnostic messages look good? I did not find Module:ScribuntoUnit/testcases. --Derbeth talk 20:01, 2 January 2014 (UTC)[reply]
Great. But perhaps we should name it assertStringContains in case we later implement a method that checks if a table contains a given table key? And yes, we should have tests for the assertions as well. I'm not really sure how to write good tests for a testing module, but I started experimenting on Module:ScribuntoUnit/testcases. – Danmichaelo (talk) 08:42, 3 January 2014 (UTC)[reply]