arquillian / arquillian-extension-warp

Arquillian Warp fills the void between client-side and server-side testing. Write client-side tests which assert server-side logic.
https://arquillian.org/arquillian-extension-warp/
Apache License 2.0
15 stars 31 forks source link

Tests in module arquillian-warp-api are never run #229

Open rhusar opened 2 months ago

rhusar commented 2 months ago

It looks like these are only meant to be 'compiled' but never run but the execution was never disabled in maven.

These tests would require the impl to be available, so they need to be reworked to Mocks.

2024-09-30T12:06:54.2882433Z [INFO] --- maven-surefire-plugin:3.2.5:test (default-test) @ arquillian-warp-api ---
2024-09-30T12:06:54.2983145Z [INFO] Using auto detected provider org.apache.maven.surefire.junit4.JUnit4Provider
2024-09-30T12:06:54.4278328Z [INFO] 
2024-09-30T12:06:54.4286272Z [INFO] -------------------------------------------------------
2024-09-30T12:06:54.4287067Z [INFO]  T E S T S
2024-09-30T12:06:54.4287771Z [INFO] -------------------------------------------------------
2024-09-30T12:06:54.7302452Z [INFO] 
2024-09-30T12:06:54.7303037Z [INFO] Results:
2024-09-30T12:06:54.7304547Z [INFO] 
2024-09-30T12:06:54.7327997Z [INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0

FYI @WolfgangHG - this one is quite funny :-)

WolfgangHG commented 2 weeks ago

@rhusar Do you mean those two? grafik

Do you have any idea what to do about them? I browsed the history, and the initial commit from 2012 still contained @Test annotations and some mocks for variables, but this was removed afterwards, further methods were added, but none are invoked.

So I have no idea what this piece of code should actually do and why parts of the class were removed ;-).

rhusar commented 2 weeks ago

Yes, those in API module. I think these were meant to be just mocks, just to avoid accidentally breaking the API contract, but for some reason that was dropped and never restored. But those are compiled, so basically, little to lose here anyway,...

WolfgangHG commented 2 weeks ago

Your explanation sounds reasonable ;-). So, what to do about them and this issue?

rhusar commented 2 weeks ago

I suppose just make them @ Test -s again and use mocking.

WolfgangHG commented 2 weeks ago

OK, I will take a look the next few days. But I will have much more questions on the way ;-)

WolfgangHG commented 1 week ago

@rhusar Help ;-)... This issue turns out to become a Mockito tutorial...

I started with the first method in TestObserverBuilderAPI:

public void testFilterBuilderUriNot() {      
    Warp
        .initiate(activity)
        .observe(request().uri().not().endsWith(".jsf"))
        .inspect(inspection);
}

..and tried to split it to pieces and mock it:

public void testFilterBuilderUriNot() {
  WarpExecutionBuilder mockBuilder = Mockito.mock(WarpExecutionBuilder.class);
  MockedStatic<Warp> mockWarp = Mockito.mockStatic(Warp.class);
  mockWarp.when(() -> Warp.initiate(activity)).thenReturn(mockBuilder);

  WarpExecutionBuilder realBuilder = Warp.initiate(activity) ;

  //call "observe":
  SingleInspectionSpecifier mockInspectionSpecifier = Mockito.mock(SingleInspectionSpecifier.class);
  //this line fails - "HttpFilters.request()" returns null.
  Mockito.when(realBuilder.observe(request().uri().not().endsWith(".jsf"))).thenReturn(mockInspectionSpecifier);

  SingleInspectionSpecifier realInspectionSpecifier = realBuilder.observe(request().uri().not().endsWith(".jsf"));

Should I mock "HttpFilters.request", too (and all the chain down)?

  MockedStatic<HttpFilters> mockFilters = Mockito.mockStatic(HttpFilters.class);
  //what should "request()" return? A mock to `HttpFilterBuilder`?