DEV Community

Olivier Lemaitre
Olivier Lemaitre

Posted on

Test, review & document your code with Amazon Q Developer

This year, at re:Invent 2024, there were a few announcements about Amazon Q developer. Among these announcements, three new agents looked interesting to me.

The first agent should generate your documentation (/doc), the second agent should generate your unit tests (/dev) and the third agent should review your code vulnerabilities (/review).

So this is what I evaluated in this blog post.

I started from this simple feedback application, with this simple architecture:

Image description

And the code I used is right there: https://github.com/welcloud-io/wio-from-diagram-to-code-with-amazon-q-developer/tree/main/feedback-app-project-from-diagrams, so you can reproduce this from it.

/doc to document your application

So among the new agent I choose the doc agent, to create a README.md file that does not exist yet

Image description

Image description

Once done, I accept the generated README.md, which will be created in my folder

Image description

The result is not bad, and when I verify what has been generated that seems correct. I don't really see any correction to apply, at least they are very small like adding more arguments to the cdk commands, but compared to the time I saved against writing it on my own, it's negligible.

Image description

However I am a bit disappointed with the diagrams and I would like to add more.

Lets start a new documentation task:

Image description

Then, I don't create, but update the existing readme file...

Image description

...with a specific change

Image description

And ask it add a sequence diagram

Image description

And it naturally adds a mermaid sequence diagram, in the right section (dataflow)

Image description

I accept it and preview the diagram, and the result is not bad at all, at least better than the original data flow for me.

Image description

I think I could add more things, but at least what we have to understand is that this agent has to be used in an iterative process, and the documentation will not be generated in one go.

/test to test your code

Now I want to add more tests to my code, so I will use the new /test agent.

For that I have to open the file which contains the code I want to test, in my case the send_feedback.py.

Image description

It proposes to specify a function, but since I just have only one function...

Image description

I directly press enter

Image description

After a few seconds I can see the test that will be placed in a new generated test file

Image description

I accept the tests...and I run them.

Very quickly, after just a few modifications, they are all running (7 tests, 130 lines of code). Again, compared to the time I would have needed to write these tests on my own it's negligible.

Image description

Now I will intentionally introduce an error and see if it's covered (therefore detected) by my new test suite. So, I remove the feedback field in my table update instruction:

Image description

Image description

and here is the result

Image description

So now I should be able to refactor my code safely. Pretty interesting!

/review to review your code

Then, before committing I want to review my code, so I will use the /review agent

Image description

I will choose review workspace

Image description

And I get all the issues in my code, so there is no critical issue

Image description

for example it detects there is no encryption of my DynamoDB database

Image description

From there I can view the details of this weakness (CWE),

Image description

You can also ignore the issue, or ask to fix it

If I want to fix it, I can first see the suggested code, and accept the fix

Image description

My code is updated

Image description

And the issue disappears from my list

Image description

Conclusion

I am not really looking for more agents with Amazon Q Developer, I believe we have so much to explore and discover with what exists that I don't want to feel overwhelmed, not knowing what to choose.

However, a think that specialized, well defined agents can incredibly increase the quality of our work and save time.

So, after I tried this agent for just a few hours, I feel I can already get value from them, at least they are a very good starting point for the things we sometimes are discouraged to do.

Top comments (0)