开发者

How do you test code without uploading to the web server? [closed]

开发者 https://www.devze.com 2023-01-27 21:01 出处:网络
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
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 5 years ago.

Improve this question

(This is a high level software development question)

I'm running a web app. In the past, to test new features, I have uploaded under a subdirectory such as test/. This generally broke all the URLs, so I'd have to redo the URLs in the test code. Then I'd have to rename all the URLs when I pushed it to the main site. I'm sure there's a better way but don't know what people usua开发者_开发技巧lly do.

Do you install a web server on your laptop? I could always buy a cheap computer and run it as a test web server, I suppose.

Eventually I'd like to have a version control system with a friend also coding, so maybe we'd both need to install Apache and MySQL on our laptops? That way we don't interfere with each other when testing new code.


Two answers:

  1. Unit test! Write tests for your code that aren't dependent on a web server.
  2. Yes, you install a web server on your laptop.

This need not be a big deal at all, depending on your platform. If you're developing Ruby on Rails apps, there's a web server built in, and others easily installable. A local copy of Tomcat or Apache is no problem. For IIS you need to be running the right version of Windows, I think, but I haven't worked in that sphere in a while.

in a pinch you could run a server environment inside a virtual machine. This has the advantage of making it easier to replicate the precise environment of your actual server. Occasionally you may run across an situation where something works fine on your own machine but doesn't work on the server, due to a permissions issue or an environment setting or some such. These can be a pain to debug. A VM that clones your server environment is one way to avoid these.


Set a configuration parameter in a file so that your URLs don't break, and just change the config file when you go between your test and main environments. You'll want this functionality anyway before you go live, in case part of your environment keels over and you need to switch boxes quickly. You should include DB connection strings, environment-dependent URLs, and anything else that changes between environments.

Unit test, unit test, unit test. If you need higher-level tests, write the lowest-level test that will do the job. Use mocks to limit the interactions with other components to just the component you want to test.

You will still want to test in a test environment of some sort on a regular basis, but you can limit how often you need to do this and how reliant you are on those tests to give you a picture of your product's current quality with the techniques above.


  1. Use something like JUnit for java ..
  2. Yes, install a local tomcat or whatever webserver you run in production environment, with eclipse IDE it's pretty simple to even debug the code .. still talking java ..


You should have a development version of the app running locally on your work computer. Depending on your web framework, this can be easy or hard. For example, grails has tools that allow you to easily run locally. But no matter, you should definitely do this. To much can go wrong pushing things to servers, especially servers that are used to production. Invest the time and get set up properly.

And, as the other answers point out, unit test.


You and your friend can install a WAMP/LAMP stack on each of your laptops. If you need a version control system, you can both use SVN or Git.

Structure your folders so they replicate the production server's directory structure. That way you don't have to rewrite URLs when deployment time comes. Virtual hosts will help you a lot.


I test locally, running a local We Server and/or App Server seems pretty normal to me.

You may well also have "staging" servers where things are opened up to larger communities.

With some care you can also make your links relative, so that you can parallel-run old and new versions on the same server, deploying with different Context Roots. For large-scale systems this tends to be very useful: you can cut over different communities of users to the new system, giving a gradual roll-out.

I do agree that Unit testing without a server is also important, but sometime before you let the users onto a new version you do really need to run on a Server.


Any particular language or technology, or just in general?

My work now is mostly web applications in Java and Python

  • For the Java code, I have the entire company source tree checked out and built on my local machine, and when I want to test, I run the jetty webserver locally to test the deployment.

  • All our code also has unit tests written for them, and there are unit testing packages for pretty much any of the common languages in use.

  • For Python, my work is mostly in django so I use the included test server.

  • I run a local instance of lighttpd to test web stuff in general. Light weight, easy to configure.

  • If you want to test actual UIs to see if things behave as you expect, or to ensure you didn't break them, you can set up Selenium locally, or Mechanize.

  • For the company at large, we have two environments - a QA sandbox, and the production environment. The QA sandbox is a server where developers deploy their applications to first, and then they test to make sure everything works as expected before deploying to production.

  • As version control, we use subversion, but most developers use either git-svn or hg-svn to be able to do version control on their local machine before pushing changes back to the central subversion server.


I prefer to use virtual instances. If you standardize your infrastructure, then it's simply a matter of copying over a "production" instance of your server to your local machine. This gets rid of most of those problems of "hmmm... it was working on my machine".

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号