{"action":"created","issue":{"url":"https://api.github.com/repos/TNG/JGiven/issues/308","repository_url":"https://api.github.com/repos/TNG/JGiven","labels_url":"https://api.github.com/repos/TNG/JGiven/issues/308/labels{/name}","comments_url":"https://api.github.com/repos/TNG/JGiven/issues/308/comments","events_url":"https://api.github.com/repos/TNG/JGiven/issues/308/events","html_url":"https://github.com/TNG/JGiven/issues/308","id":215265878,"number":308,"title":"support for repetitions","user":{"login":"adrian-herscu","id":2996545,"avatar_url":"https://avatars2.githubusercontent.com/u/2996545?v=3","gravatar_id":"","url":"https://api.github.com/users/adrian-herscu","html_url":"https://github.com/adrian-herscu","followers_url":"https://api.github.com/users/adrian-herscu/followers","following_url":"https://api.github.com/users/adrian-herscu/following{/other_user}","gists_url":"https://api.github.com/users/adrian-herscu/gists{/gist_id}","starred_url":"https://api.github.com/users/adrian-herscu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/adrian-herscu/subscriptions","organizations_url":"https://api.github.com/users/adrian-herscu/orgs","repos_url":"https://api.github.com/users/adrian-herscu/repos","events_url":"https://api.github.com/users/adrian-herscu/events{/privacy}","received_events_url":"https://api.github.com/users/adrian-herscu/received_events","type":"User","site_admin":false},"labels":[{"id":123040568,"url":"https://api.github.com/repos/TNG/JGiven/labels/core","name":"core","color":"5319e7","default":false},{"id":91681259,"url":"https://api.github.com/repos/TNG/JGiven/labels/enhancement","name":"enhancement","color":"207de5","default":true},{"id":507287746,"url":"https://api.github.com/repos/TNG/JGiven/labels/under%20discussion","name":"under discussion","color":"006b75","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":7,"created_at":"2017-03-19T14:01:04Z","updated_at":"2017-03-22T19:22:25Z","closed_at":null,"body":"Sometimes a test is required to repeat a step or a sequence of steps in order to simulate some real behavior.\r\n\r\nFirst I tried to use TestNG's invocationCount + threadPoolSize of @Test annotation. Then discovered that every invocation is rendered in the report. Having 100,000 invocations would make the report so big as it would be unusable.\r\n\r\nThen I tried to write a step that accepts a TestNG class and repeatedly runs all its tests. Tried to implement it as follows:\r\n\r\n    public SELF repeating_$_times(\r\n        final int times,\r\n        final Class<?> scenario) {\r\n        IntStream.rangeClosed(1, times)\r\n            .parallel()\r\n            .forEach(i -> {\r\n                log.debug(\"repeating {}\", i);\r\n                final TestNG testng = new TestNG();\r\n                testng.setTestClasses(new Class[] { scenario });\r\n                testng.addListener(new ScenarioTestListener());\r\n                testng.run();\r\n            });\r\n        return self();\r\n    }\r\n\r\nHowever, when running it, something is not correctly initialized within JGiven. So fields that should be injected are not. It also requires a public class which also get executed and rendered independently.\r\n\r\nFinally I tried to make a repeat step method that accepts another step method and just calls it repeatedly. Tried to implement is as follows:\r\n\r\n    public SELF repeating_$_times(\r\n        final int times,\r\n        final @DescriptionFormatter.Annotation Function<SELF, SELF> functor) {\r\n        IntStream.rangeClosed(1, times)\r\n            // .parallel() // DOES NOT WORK\r\n            .forEach(i -> {\r\n                log.debug(\"repeating {}\", i);\r\n                safely(dontcare -> functor.apply(self()));\r\n            });\r\n        return self();\r\n    }\r\n\r\nThis one works with two issues:\r\n\r\n1. the repeated step is not described in the report (hence I wrote a DescriptionFormatter and wrapped the functor object to include a description, just to have something in the report)\r\n2. running the repetition in parallel does not work if the repeated step uses ThreadLocal variables\r\n\r\nIs there a solution I am missing?\r\nThis is a real scenario, I think it is worth framework support.\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/TNG/JGiven/issues/comments/288510826","html_url":"https://github.com/TNG/JGiven/issues/308#issuecomment-288510826","issue_url":"https://api.github.com/repos/TNG/JGiven/issues/308","id":288510826,"user":{"login":"adrian-herscu","id":2996545,"avatar_url":"https://avatars2.githubusercontent.com/u/2996545?v=3","gravatar_id":"","url":"https://api.github.com/users/adrian-herscu","html_url":"https://github.com/adrian-herscu","followers_url":"https://api.github.com/users/adrian-herscu/followers","following_url":"https://api.github.com/users/adrian-herscu/following{/other_user}","gists_url":"https://api.github.com/users/adrian-herscu/gists{/gist_id}","starred_url":"https://api.github.com/users/adrian-herscu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/adrian-herscu/subscriptions","organizations_url":"https://api.github.com/users/adrian-herscu/orgs","repos_url":"https://api.github.com/users/adrian-herscu/repos","events_url":"https://api.github.com/users/adrian-herscu/events{/privacy}","received_events_url":"https://api.github.com/users/adrian-herscu/received_events","type":"User","site_admin":false},"created_at":"2017-03-22T19:22:25Z","updated_at":"2017-03-22T19:22:25Z","body":"I think that a good enough general solution would be that JGiven should render Java lambda expression blocks. Currently, it just calls toString() and plots that into the report.\r\n\r\nThis would open the possibility to implement generic steps such as\r\n\r\n- repeat(int, Function<SELF,SELF>) - a step that repeatedly calls Function\r\n- safe(Function<SELF,SELF>) - a step that swallows exceptions generated by Function\r\nand looking at JMeter and other testing tools there might be more ideas.\r\n\r\nNow, one has to code the same loop, or try-catch and build a new step method just for looping or handling exceptions. "}}
{"actor":{"display_login":"adrian-herscu"}}