Closed nockc closed 6 years ago
Hi I'm interested in this issue.
I'm new to writing tests in TEAMMATES and need some help here. I studied the tests written in test/cases/action
and got a rough idea of to approach this (please correct me if I'm wrong):
gaeSimulation.loginAsAdmin(adminUserId); // simulate an instance
AdminExceptionTestAction testAction = getAction(submissionParams); // create an object of this test action with the necessary submission parameters
RedirectResult result = getRedirectResult(testAction); // an object that holds the redirect page
I have some queries regarding this issue:
1) How do I trigger the exceptions checked by AdminExceptionTestAction
? How can I replay the process in my browser? I tried it on my dev server by creating an admin and visiting localhost:8080/admin/adminExceptionTest
and it returns me the pageNotFound.jsp
page, which leads to me second question.
2) Where are the exceptions thrown back in the end? How do we catch those and compare them in this test file? I debugged the code and found out that the Action's class public ActionResult executeAndPostProcess
calls the execute
method and catches the EntityDoesNotExistException
.
@TEAMMATES/seniordevs any advice?
@tanhengyeow in the meantime try a different issue.
@tanhengyeow do you know how to pass parameters to HTTP GET
/POST
? (this one should be a GET
which is the simpler one)
@tanhengyeow I assume that you have an Idea of how to add submission Parameter And HTTP GET/POST method
Now coming to your answer
Suppose that after working with some parameter you wish to get some Particular Page i.e. expectedPage (expectedPage depend on your logic)you can verify it by making test case of those parameter and pass the parameter to get actualPage and use the method
AssertHelper.assertContain(expectedPage,actualpage)
to check expected and actual page are same or not if they are same your test case passes else fail . many a times redirect does not occur properly you can check it by assetFalse(result.isError)
. You can Mention me in the comment if required further information
Hi @wkurniawan07 @shaharyar-shamshi
Thanks for the tips! Went on to work on other issues before coming back to this one :smile:
I figured out how to trigger the exceptions manually in the browser. If anyone is interested or following this, this is how to do it:
http://localhost:8080/admin/adminExceptionTest?error=AssertionError
http://localhost:8080/admin/adminExceptionTest?error=EntityDoesNotExistException
http://localhost:8080/admin/adminExceptionTest?error=UnauthorizedAccessException
http://localhost:8080/admin/adminExceptionTest?error=NullPointerException
http://localhost:8080/admin/adminExceptionTest?error=DeadlineExceededException
http://localhost:8080/admin/adminExceptionTest?error=NullPostParameterException
I submitted a PR for this fix, feel free to review! Initially I wanted to perform assertEquals(expectedPage, actualPage)
but I realized getShowPageResult(action)
cannot work in this context. Further discussion can be held in the PR :smile:
Function testExecuteAndPostProcess() is missing in AdminExceptionTestActionTest.java file. Verify each exception in thrown correctly from execute function in teammates.ui.controller.adminexceptiontestaction