Hot Reload during Unit testing - testing

I develop right now a small flutter app. I think as everyone, I fell in love with the hot reload feature.
So now I'm wondering if there is any possibility to have the same developer experience during unit test. Do have to turn a flag somewhere or is it right know just no possible.
If is not possible, are there any plans to make it possible?

I guess what you want is to run the new tests as soon as they changed. But in that case it's not a hot reload. Simply a watcher that detect whenever your sources or your tests have changed and restart them.
Flutter, and the lower layers, don't implement "watch" yet. Although you can achieve a similar effect quite easily using a node packages
npm i -g watch which will install watch globally so that you can use it in as a command line.
and then in your terminal do
watch "flutter test" lib test which will run flutter test everytime something change inside lib and test folders

You need to run the unit test as an app to be able to use hot reload.
In IntelliJ you can copy the run configuration for lib/main.dart and then select the file test/my_test.dart in the copy.
There is no support to run single tests from a set of tests in a test file in IntelliJ (don't know other IDEs) when you run a test this way.
In my opinion, if you run it as unit test, hot reload doesn't bring much benefit anyway because execution is very fast.

Related

Do I have to rebuild my frontend for production every time I edit it? I'm using Vue

Basically what I have is my frontend (Vue) and my backend (Node.js and etc.). By following a guide, I've built the frontend for production using npm run build. I got a bunch of files in a build folder I setup within a previous step. These files were then moved to a folder in the backend. It works, but it's more a demo than anything else, and the frontend and backend will have to be modified more as I continue.
I'm just wondering if and when I edit the fronted more (let's say, when I add a new page) am I supposed to go through this process again? So I'll modify the front end folder, build that, move files, etc.
Thanks.
Yes, definitely.
If we are in a development environment, we use npm run dev or yarn run which upholds the development environment running and updates the browser whenever any modifications inside the code happen. We don't use any final build in the development environment because we make code modifications so repeatedly that it would be a sore process to make a build after every modification and check the results using that build.
But, the production is distinct from the development environment. We deploy the only code which is bug-free, entirely working, and ready for users to use. Deploying to production means all changes have been made, and the final code is ready to be deployed. So, we make a final production build and deploy it to our server.
So, don't panic to deploy to production every time you make a small change in the code. First, complete your all changes, and test the changes in the development environment, if everything is working correctly then only create a final production build, and deploy it to the server.**
I hope this helps.

Is there a way to reflect the changes done in a java project(in Intellij) while debugging/not debugging without having to rebuild the project

I have a project that takes quite sometime to build and it becomes difficult to rebuild again and again after testing if I do some fix. I was wondering if there was a way in which I could do the hot fix test it without having to rebuild whole module. I am using Intellij. Any help is highly appreciated.
While debugging you can change the values with Intellij and apply them before the line is executed without the need to recompile. Here is the official documentation from Intellij.
While not debugging it's kinda impossible unless you use a plugin, for example, you can hot reload using JRebel

Get compile time in react-native?

Is there a way to get the compile time (time at which i compiled the app, e.g. in utc or local). The reason I want this is that I often am not sure what version my emulator is running right now and adding a text widget at the top with the compile time would give me this security while developing.
One way I would do that :
make a shell script that runs before build, and gets current system time
(for iOS, this can be done adding a script phase before your build phases, on android, you need to change your gradle, see : execute task before android gradle build?)
Inject that time into a .env file, then use react-native-config to recover this 'buildTime' variable and display it.
There must be other ways to do that, but no ready-to-use tool to my knownledge, you will have to dive into Platforms specific build scripts ...

Add tools to ionic serve

I have written many build scripts in package.json using npm, but now that we are looking at Ionic, I want to include additional tools into the internal build process of Ionic. For instance, we use a started template, and then ionic serve to have the build process run, compile, update the website, then watch for changes.
I want to add the lint process before the build, and then the test execution after, before the page refreshes. Once the page is refreshed, then other tools for documentation could run (typedoc, angular2-dependency-graph, etc). I have seen the customization options, but that is not really what I am trying.
Looking into the ionic-app-scripts, it appears that I would have to extend the script by calling the JavaScript functions directly. Ideally, I just want to add some additional npm lines into the build process.

With Continuous Integration, why are tests run after committing instead of before?

While I only have a github repository that I'm pushing to (alone), I often forget to run tests, or forget to commit all relevant files, or rely on objects residing on my local machine. These result in build breaks, but they are only detected by Travis-CI after the erroneous commit. I know TeamCity has a pre-commit testing facility (which relies on the IDE in use), but my question is with regards to the current use of continuous integration as opposed to any one implementation. My question is
Why aren't changes tested on a clean build machine - such as those which Travis-CI uses for post-commit tesing - before those changes are committed?
Such a process would mean that there would never be build breaks, meaning that a fresh environment could pull any commit from the repository and be sure of its success; as such, I don't understand why CI isn't implemented using post-commit testing.
I preface my answer with the details that I am running on GitHub and Jenkins.
Why should a developer have to run all tests locally before committing. Especially in the Git paradigm that is not a requirement. What if, for instance, it takes 15-30 minutes to run all of the tests. Do you really want your developers or you personally sitting around waiting for the tests to run locally before your commit and push your changes?
Our process usually goes like this:
Make changes in local branch.
Run any new tests that you have created.
Commit changes to local branch.
Push local changes remotely to GitHub and create pull request.
Have build process pick up changes and run unit tests.
If tests fail, then fix them in local branch and push them locally.
Get changes code reviewed in pull request.
After approval and all checks have passed, push to master.
Rerun all unit tests.
Push artifact to repository.
Push changes to an environment (ie DEV, QA) and run any integration/functional tests that rely on a full environment.
If you have a cloud then you can push your changes to a new node and only after all environment tests pass reroute the VIP to the new node(s)
Repeat 11 until you have pushed through all pre-prod environments.
If you are practicing continuous deployment then push your changes all the way to PROD if all testing, checks, etc pass.
My point is that it is not a good use of a developers time to run tests locally impeding their progress when you can off-load that work onto a Continuous Integration server and be notified of issues that you need to fix later. Also, some tests simply can't be run until you commit them and deploy the artifact to an environment. If an environment is broken because you don't have a cloud and maybe you only have one server, then fix it locally and push the changes quickly to stabilize the environment.
You can run tests locally if you have to, but this should not be the norm.
As to the multiple developer issue, open source projects have been dealing with that for a long time now. They use forks in GitHub to allow contributors the chance to suggest new fixes and functionality, but this is not really that different from a developer on the team creating a local branch, pushing it remotely, and getting team buy-in via code review before pushing. If someone pushes changes that break your changes then you try to fix them yourself first and then ask for their help. You should be following the principle of "merging early and often" as well as merging in updates from master to your branch periodically.
The assumption that if you write code and it compiles and tests are passed locally, no builds could be broken is wrong. It is only so, if you are the only developer working on that code.
But let's say I change the interface you are using, my code will compile and pass tests
as long as I don't get your updated code That uses my interface.
Your code will compile and pass tests as long as you don't get my update in the interface.
And when we both check in our code, the build machine explodes...
So CI is a process which basically say: put your changes in as soon as possible
and test them in the CI server (it should be of course compiled and tested locally first).
If all developers follow those rules,
the build will still break, but we will know about it sooner rather than later.
The CI server is not the same as the version control system. The CI server, too, checks the code out of the repository. And therefore the code has already been committed when it gets tested on the CI server.
More extensive tests may be run periodically, rather than at time of checking in, on whatever is the current version of the code at the time of testing. Think of multi-platform tests or load tests.
Generally, of course, you'll unit test your code on your development machine before checking it in.