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 9 years ago.
Improve this question
`
Blockquote
How to write test class to test action classes using mockito?
Are you using JUnit? Think about having one test method for each requirement that your class has to meet, or each particular scenario of a requirement. Once you've planned out what each test method will be, work out
what you need to set up in each test method,
what the actual call to your class will look like within the test method,
what you need to verify at the end of the test method.
Use Mockito when any of your test methods are likely to use functionality outside of the class that you're actually trying to test. Mocking is all about removing the behaviour of other classes (collaborator classes) from what happens during your test. Once you've identified what these other classes are, and what behaviour you want from them, then you can start using Mockito.
But you really need to plan out your tests first. Mockito is not a silver bullet that will test things for you.
I'm sorry, but I really can't give a more detailed answer than this, unless you would care to add some detail to your question. Right now, your question is remarkably vague.
Related
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
More I am diving into documentation of Jest and Its real world use cases. Lesser I am thinking that writing unit test for every other component is not compulsion. Am I missing on something? can someone please guide me here.
My idea is when we are using react to create MVP we tend to write a lot of dynamic code. It is of course impossible to test those for all cases because of some compromised design choices. When testing follow the principle of what you are testing. i.e. You do not want to test if react does it's job of batching and updating states. What you may want to test is if the functions are executed and when they are if they result a proper props. React-testing-library has matured enough to support those. Jest is great for your logic functions i.e. when your are deriving some props of a component from a state. You want the props to be what is in your testing boundary. You don't want to count how many times you jest mocks test or spy run. Just imagine it is a controlled console.log where you mat be looking for certain results. Please do not forget about react and it's batching algorithm. I do not think anybody needs to test react and how it works. Just test your props and your state. If it gets too complex snapshot testing may be the way to go.
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 7 years ago.
Improve this question
When you execute your Alloy-code in Analyzer you get some message like "No counterexample was found". And I want extract this message. I want, for example, get .txt file with this message. Can somebody help me?
The cleanest and easiest way to do this would be to write a small java program that makes calls to the Alloy API to analyze given models and write the result in a text file (example here).
Now if you want to choose the hard and dirty way, that is: to extract such information from the guenuine Alloy analyzer GUI (not from a program of your own that calls the Alloy API),I guess a solution could be to use image recognition scripting tools like sikuli.
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 6 years ago.
Improve this question
It's been a really long time since I worked with UML Diagrams.
I started working with UML Use Cases again, for a real world project. I would like to ask some questions.
How should I approach writing use cases?
I believe the tasks that leads to a "Major/Bigger" task should not be considered as use cases by themselves. Am I right?
Okay, what if I have a task like View tutorial and it has Comment on Tutorial, Favourite Tutorial, etc. Should these be separate use case, Extending View Tutorial? If yes, but, aren't they small features, why we should include them?
I'm mixing some stuff here, I hope someone could enlighten me .
Thanks!
Read Alistair Cockburn's Effective Use Cases book (see it on Amazon: 1). He does an excellent job of explaining practical use of use cases in a structured and effective way.
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 6 years ago.
Improve this question
I am working on a function that returns an object from a container (e.g an Array) by value (e.g by name). If the object doesn't already exist, then a default copy of the object (default constructor) is created and returned.
That way, this function ALWAYS returns an object, regardless if the object existed prior to calling the function.
Now my question is this: how to name this function? GetOrCreateThenGet sounds stupid. Any ideas?
Edit : I feel something like this would be closer to the function's essence: GetForSure...
The best suitable name for the function would be "Provide" like if you provide goods you can ship it from a warehouse or make/buy a new one and then deliver.
Why do you need anything other than getXXX(). Any method that has and/or means that it is doing to much and is mixing concerns and seriously breaking the Single Responsibility Principle.
Should the caller actually care if the object is being created on demand if all they need from the contract is to get the object?
getOrCreate implies you will get the object or it will be created but not returned.
Again why would I care about the create part?
If I really am supposed to care it would be getOrCreateAndGet to be semantically correct, but highly unorthodox and prone to discussions with peers about methods doing to many things and mixing concerns and breaking the Single Responsiblity Principle? Just because other people name things whacky and non-sensical isn't a good excuse to do it wrong also.
GetGuaranteed seems to cover all the caller needs to know...
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 4 years ago.
Improve this question
looking into the nodejs server stack with nodejs/express and mongoose
What is considered a best practice solution?
(1) Creating a mongoose datamodel module then working with the model objects
(2) Creating a wrapper datalayer module that will internally use the mongoose model
Pros for (1)
I really like the OOP style classes mongoose gives me, add my own methods, my own setters and getters, I can add validation and event-handlers, and use the DataModel without redefining it in another module.
Pros for (2)
I should be able to mockup the data layer with simpler implementation (tests, etc..)
or switch a database if needed.
What do you think?
I usually start with the easiest and least complex option to start and only move to a more complex one when it's really needed. So in this case I always start with Option 1 and have yet to find an instance where I wish I had started with Option 2. If I really need to change databases, I'll do the work then instead of doing more work upfront for something I may never need.
Keep in mind that this depends on how big of a project it is and how many people are working on it. If it's a small team (or just you) extra layers of abstraction generally aren't needed. If it's a large project with a large team, I'd take a bit longer figuring out the best architecture for long term maintainability.