How to test frontend and APIs? [closed] - unit-testing

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 1 year ago.
Improve this question
intro: i'm currently taking a course at my university where we do TDD and BDD. We haven't learned anything about how to do frontend test except that we should never do BDD or TDD by testing the view layer since any changes to this layer would mess up all the tests. We've only worked in java and within the business logic layer (we've not even learned about persistence).
question(s):
I am working on an application using BDD methodologies. The BDD helped me implement the business logic. I am using hibernate ORM and mysql for the persistence. And it seems safe to assume any malfunctions in the persistence layer would also make the tests for the business logic fail. Is that correct to assume or is it also necessary to write tests for a database even though the business layer tests would fail if something is wrong in the persistence layer?
if i were to implement an API in the application layer and have a frontend written in react. Should i then do modular tests of the components and write a seperate test for the API (application layer)? the software written in the api that's using the business logic could be wrong and therefore i assume it would be a good idea also to test this part.
I've searched a lot on the internet and here and it seems like there are tools for testing frontend (jest) and selenium or postman for API tests. I assume i can reuse my feature description for all the layers but isn't there some easier way to test all layers? and is this really the best and easiest way to test an application?

Related

Using Karate or Postman [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 1 year ago.
Improve this question
I am new to Karate and I am wondering which is a better tool for api testing, postman or karate ? Both tools are easy to use but I wonder in long term which is a better tool in terms of automation testing. My aim is to automate the api tests and run them through CI/CD pipeline jobs.
Anyone who has moved to karate from postman, could you please share your experiences on how easy was the migration, what method have you used to migrate postman collections, what benefits have you observed so far by choosing karate.
Thanks in advance.
We evaluated Postman, Karate, and a few other frameworks about three years ago when Karate was still in it's infancy. Postman did have a lot of pull just because our dev team had a very solid collection that was well maintained, but we quickly realized Postman was not scalable, and simply did not have the features necessary for an automation framework.
We will be starting api testing at my current job sometime this year, and Karate is again the most likely candidate, though we will also consider Postman and Cypress, the later mostly because we are using it for front-end. But Karate is so easy to use out-of-the-box, has BY FAR the best documentation, and real-time support of any open source framework I've used, and has outstanding integration for DB connections, GraphQl calls, Java interop, and javascript-like syntax.
I love Postman for quick exploratory testing, but for test framework and CI, I don't see how they can compete.
Started testing APIs with Postman and looked for a tool that was better for developers to share their "API knowledge" via GIT.
Came across Karate three years ago and I use it for almost every API call have to make.
Postman is a tool for non developers and for people afraid writing any kind of code.

What are the pros/cons using serverless framework vs aws sam? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 2 years ago.
The community reviewed whether to reopen this question 1 year ago and left it closed:
Original close reason(s) were not resolved
Improve this question
I'd like to choose a framework for building and deploying AWS services and I need to have a full list of pros/cons to justify one framework over the other. Since this forum doesn't want people to just post opinions please provide references with your responses. Also, I'd like to hear from people who have deployed production solutions using any of these frameworks.
If you are looking at building Serverless applications I would select the Serverless Framework. For a couple very large reasons:
The community is a lot bigger. This may not seem like a big deal but with the community contributions constantly improving the framework itself as well as the huge quantity of community plugins to the core framework that extends the functionality out to an enormous amount, it makes it difficult to justify anything else.
Documentation quality is amazing. The Serverless Framework has a huge depth of documentation, everything from reference docs for every feature of the framework to full (and free) courses about building Serverless applications and blog posts with details on best practices. Then there is the examples repos, guides, tutorials ... its pretty awesome!
The ability to use and mix multiple cloud vendors. SAM is AWS exclusive,so if you wanted to potentially create services in other cloud vendors such as Azure or GCP, you would be stuck. But its not just the big boys either; Twilio, IBM Cloud, Cloudflare, Tencent, OpenWhisk and more are all supported.
Free monitoring and management platform. The team at Serverless Inc also produce a pretty stellar SaaS platform at dashboard.serverless.com that provides a lot of the "missing" capabilities needed for application development such as monitoring, debugging, troubleshooting, CI/CD and a bunch more!
Components makes deploying specific use cases a piece of cake. Components is one of the newest projects to come out of Serverless, Inc and promises a shift in how we build Serverless applications that is far more use case driven but also focusses a lot more on the developer experience. Something to definitely keep your eye on.
So yes, I would suggest the Serverless Framework for a lot of really compelling reasons!

Are Spring/Micronaut repository tests necessary [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 2 years ago.
Improve this question
Hello stackoverflow community.
I had an argument at work regarding if repository tests for spring-data JPA (or the Micronaut version) are necessary at all.
This would be my setup of the application:
#Controller ➡ #Service/#Sigleton ➡ Repository<Entity>
in my service tests I'd use the #ExtendWith(SpringExtension::class) extension (Junit5)
when creating the test setup, I'd #MockBean away other systems I need to call (like REST-APIs) but #Autowire my Repository's.
When setting up my test data I'd simply save my required entities into an H2 in-memory database by using the injected repositories.
This will test my database logic and business logic as well. In case of 100% test coverage I've tested all the database calls which can happen in production.
However what I usually see in projects is that the Repository is mocked away.
To test the custom repository calls there are separate Tests to make sure the repository functions work as expected.
What are your comments on this. Do you prefer the approach without repository mocks or with and why?
I have no experience with Micronaut, but I believe my answer will apply to both of the frameworks:
There are different types of integration tests supported by spring for example.
Basically the fact that you're running a spring context in the test, already means that its more than a unit test. In general the Spring test package is for integration tests.
Now in Spring there are annotations like #DataJpaTest, #WebMvcTest. They create a "slice" of application context loading only necessary beans, and mocking / omitting others. For example, in #WebMvcTest the JPA repositories are anot loaded at all.
You can also create your own slices.
Now If you want to check your rest layer (Controller is defined correctly, request is validated in a proper way, upon the request you're getting a response in a proper format and so forth) you can use #WebMvcTest.
If you want to test that the sql queries are correct - that you can use #DataJpaTest (assuming you work with JPA / Spring Data of course).
Now, If you want to test service logic, sometimes you don't even need an integration test (loading spring context) since you can run a unit test for services and mock out the repository calls or calls to external services if you have those.
Regarding the H2 approach. While people use it for testing their DB layer (SQL queries), sometimes it doesn't work exactly like your database in production. This means that sometimes you can't really run the same SQL query in tests. For these cases I recommend TestContainers project: run the Docker image of your db on startup of the test and stop the image after the test ends.
Update
Based on OP's comment:
lot of the 'mysql query' is already been taken care of by the framework, so why should I explicitly test the repository
This is subjective, but let me put it this way: Tests are a tool to gain a confidence a code for developer first of all.
If the developer wants to be sure that the query behaves as expected then the test is a tool that can help. Specifically regarding Queries: Maybe the query is just wrong, maybe its a native query that should be checked anyway. Maybe there are many queries that run one after another. Its only up to you to decide.
Is it worth it to write Unit tests for services?
Well, this depends on what do the services actually do.
If they run a complicated algorithm that can't be easily checked by integration tests (like service requires various mocks in various cases) then unit tests for services can be done.
Besides, in general, unit tests are way faster than Spring's tests. So (again subjective) my personal rule is: if you can gain the confidence in code with unit test - do it. If you need to check integration - go for integration test.
If you are not mocking your Repository in service junits, then it is an Integration test and not a Unit test. And it is fine if you want to keep it this way.
But if you want to write unit tests, which tests your individual layers then you should mock your Repository and write separate integration tests for Repository.

How to design enterprise level application? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I am a freelance software engineer, I have worked in few areas of computer science, I have made some e-commerce websites in the past. Now I have an opportunity to build a big enterprise level system. I can not disclose specifics about the application due to NDA I signed so pardon me if my question seems broad, let me know in the comments if you require clarification. I appreciate your help.
About Application:
In this application, I would require building a system like uber, there will be people at my client's end for
resolving customer issues, so a CRM is also needed.
customers will be using this app, so I have
to design a separate system that can manage tickets and access
database.
My question is where to start designing such application. I guess I would require DynamoDB and AWS, I have divided modules into parts such as Client App, Database, Dashboard etc. I want to know if there is some case study that can help me decide how to design such large application.
I found this link useful, it gave me an idea of work, but still, I believe it's a long way from money shot.
[EDIT]
To narrow down the scope of the question, What Backend server should be chosen for an application that will serve one hundred thousand users per hour. I will use Mongo DB as the database, and Python as backend scripting language.
IBM has a nice article on Enterprise Architecture,
https://www.ibm.com/developerworks/rational/library/enterprise-architecture-maximum-value/
Before building the software, design how it should work and choose your software components according to that.
Previously you might need costly infrastructure to think something, with recent technologies, you can do them at a lower cost. You need to apply the right architecture and engineering when designing your application.

What is the production-readiness of sails.js and meteor.js, and how to they compare to Django? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
I am thinking of using either one of them in building our startup which is like a job portal with validation,verification and includes special features for freelancing and all.
Is meteor or sails good for using as a backend or should we go with more robust backend like Django? Will using javascript on our backend provide the ability to scale in the future moreso than Django/python?
I would really like some opinions in this matter to get to a decision.
sails.js and meteor are both great options for production.
Both frameworks have good real-time (socket.io) support, large/active communities, support a stateless backend design which make horizontal scalability possible, and are great for getting a web application spun up quickly.
sails.js - http://sailsjs.org
broad database support through the Waterline ORM (there are over a dozen supported databases)
concepts should more familiar to most node.js developers (it's built on express)
modeled after rails, grails, and django, so the paradigm is more familiar to developers with experience in those tools
extensible through npm package manager via express middleware and custom modules
meteor - https://www.meteor.com
better integration between the backend and frontend
project is VC-backed with a firmer corporate backing
extensible using custom package manager and extension system
built-in deployment system and hosting on meteor.com
Will using javascript on our backend provide the ability to scale in the future moreso than Django/python?
Probably. As with anything, you just have to do it right.
My overall opinion is that meteor is sort of cult-ish and monolithic, and that once you've chosen it, you're locked in. sails.js is built on express, so it's easy to split out functionality and integrate with other tools.
My disclaimer is that I work for Balderdash (the company that invented sails.js); but on that note, I can also tell you that millions of users are served by sails.js applications. We find that it's quite good, and our business is thriving because of the power of sails.js. I know folks who have used meteor with success as well.
I think this is a primarily opinion-based question, so you're going to receive answers from the very same "type".
But I can tell you one thing: Meteor is robust enough for production use, specially now that they hit the 1.1 release (https://www.meteor.com/blog/2015/03/31/meteor-11-microsoft-windows-mongodb-30).
Meteor is perfectly suited for startups, since it brings everything you need (and more) into a single "pack".
Check this: http://meteorpedia.com/read/Why_Meteor
So yah, that's my answer going for the Meteor side.. (not very technical, I know).