Hi Jurgen, 

this is an interesting use case.   Can you please create a JIRA for it and we 
can satisfy it by adding the appropriate functionality. 

Thanks

> On 23 Apr 2018, at 17:21, Jürgen Schmied <[email protected]> wrote:
> 
> I tried to find unused steps and ended up with overriding a method of 
> PerformableTree.
> 
> This is quita a hack but found 250 unused steps in our code base ;-)
> 
> Is there any better method of doing this?
> 
>     @Override
>     public void addStories(RunContext context, List<Story> stories) {
>         super.addStories(context, stories);
> 
>         Set<Method> usedMethods = new HashSet<>();
>         Set<Method> existingMethods = new HashSet<>();
> 
>         List<CandidateSteps> candidateSteps = (List<CandidateSteps>) 
> ReflectionTestUtils.getField(context, "candidateSteps");
> 
>         List<StepCandidate> collectCandidates = 
> context.configuration().stepFinder().collectCandidates(candidateSteps);
>         for (StepCandidate stepCandidate : collectCandidates) {
>             existingMethods.add(stepCandidate.getMethod());
>         }
> 
>         for (PerformableStory story : getRoot().getStories()) {
>             for (PerformableScenario scenario : story.getScenarios()) {
>                 NormalPerformableScenario sc = (NormalPerformableScenario) 
> ReflectionTestUtils.getField(scenario, "normalScenario");
>                 if (sc != null) {
>                     PerformableSteps ps = (PerformableSteps) 
> ReflectionTestUtils.getField(sc, "steps");
>                     List<Step> steps = (List<Step>) 
> ReflectionTestUtils.getField(ps, "steps");
>                     for (Step step : steps) {
>                         if (step instanceof StepCreator.ParametrisedStep) {
>                             usedMethods.add((Method) 
> ReflectionTestUtils.getField(step, "method"));
>                         }
>                     }
>                 }
>                 List<ExamplePerformableScenario> ec = 
> (List<ExamplePerformableScenario>) ReflectionTestUtils.getField(scenario, 
> "exampleScenarios");
>                 if (ec != null) {
>                     for (ExamplePerformableScenario eps : ec) {
>                         PerformableSteps ps = (PerformableSteps) 
> ReflectionTestUtils.getField(eps, "steps");
>                         List<Step> steps = (List<Step>) 
> ReflectionTestUtils.getField(ps, "steps");
>                         for (Step step : steps) {
>                             if (step instanceof StepCreator.ParametrisedStep) 
> {
>                                 usedMethods.add((Method) 
> ReflectionTestUtils.getField(step, "method"));
>                             }
>                         }
>                     }
>                 }
>             }
>         }
> 
>         
> System.out.println("#########################################################");
>         System.out.println("existing " + existingMethods.size());
> 
>         existingMethods.removeAll(usedMethods);
> 
>         System.out.println("leftover " + existingMethods.size());
> 
>         for (Method leftover : existingMethods) {
>             System.out.println(leftover.toString());
>         }
> 
>         
> System.out.println("#########################################################");
>    
>     }
> 
> 
> 
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "JBehave User" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected] 
> <mailto:[email protected]>.
> To post to this group, send email to [email protected] 
> <mailto:[email protected]>.
> To view this discussion on the web, visit 
> https://groups.google.com/d/msgid/jbehave-user/b84cc7a5-ba6a-4e1e-b07c-0b3df8385e32%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/jbehave-user/b84cc7a5-ba6a-4e1e-b07c-0b3df8385e32%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout 
> <https://groups.google.com/d/optout>.

-- 
You received this message because you are subscribed to the Google Groups 
"JBehave User" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send an email to [email protected].
To view this discussion on the web, visit 
https://groups.google.com/d/msgid/jbehave-user/B6D3E8B3-D1D0-403D-9FD7-6B6E9FF27784%40aquilonia.org.
For more options, visit https://groups.google.com/d/optout.

Reply via email to