Automated Testing with python-unit testing for Java code (1) and python Unit Testing
Python we talk about most of the time refers to python implemented by C. In this article, we want to talk about python implemented by java. Her name is Jython, you can go to the official website http://www.jython.org/look, the last 2 years is very active, the release of the new version is more, in fact, I began to contact the jython 2.1 version, however, the Community was inactive and did not continue to be applied. Recently, the company has several projects that need to release java-implemented APIs. After all, java is not so familiar. It is still not so fast to write the code for API interface testing, it's still faster to use python. python is too powerful and powerful to do anything. What I want to do is to write code for anything. The first thing I want to think of is to use python to solve the problem, then I had no pressure and didn't have much motivation to learn other languages. I don't know whether this is a curse or a blessing.
The following simple example shows how to perform unit tests on java code. A recent project needs to implement a unique ID, which is implemented using java's SecureRandom. It is difficult to repeat it. I still want to test how likely it will be repeated, test_unique implements this unit test code, which is actually a unit test for the SecureRandom method. Test_max is used for demonstration.
From java. security import SecureRandom
From java. lang import Math
These two packages are all built-in methods in JDk, not in jython. We will test these two methods.
#!/usr/bin/env jython#coding=utf8from java.security import SecureRandomfrom java.lang import Mathimport unittestimport timeimport sysclass UniqueRandomTest(unittest.TestCase): def setUp(self): self.start_time=time.time() print "starting\n", self.dic={} def test_unique(self): unique=False for i in xrange(1,100000): random=SecureRandom() a=Math.abs(random.nextLong()) if self.dic.has_key(a): unique=True print "duplicate " break else: self.dic[a]=1 self.assertEquals(unique,False) def test_max(self): self.assertEquals(Math.max(8,5),8) def tearDown(self): print "cost", time.time()-self.start_time," second" print "end"
Run the unit test and the result is
Finding files... done.
Importing test modules... done.
Starting
Cost 0.000999927520752 second
End
Starting
Cost 1.85600018501 second
End
----------------------------------------------------------------------
Ran 2 tests in 2.043 s
OK
What tools are generally used for automated software testing? Is it the same as the black box testing tool? How can I use loadrunner?
1. For your problem, first define the test type, then identify the automatic test type, and finally identify which type of automated test tool is used
1. Test types include white box testing, black box testing (function testing, performance testing), etc.
2. Different Test types use different automated testing methods. White-box testing focuses on code-level unit testing and black-box testing primarily on functional and system-level verification testing.
3. Automated Testing for white-box testing generally requires a certain programming Foundation, that is, the ability to write test code based on functional code. There are many commonly used automated testing tools for unit testing, all search online.
4. Automated Testing: for functional testing, there are several situations where testing is based on CLI, API, and GUI; testing based on CLI and API, that is, the script technology is used to simulate the sending of CLI commands or API requests to the device to control the device. Based on GUI function testing, that is, using traditional interface automation testing tools (such as RFT and QTP) to control interface control operations to simulate user operations, these methods require you to have a certain coding Foundation. You need to understand script technology (such as tcl, python, ruby, etc.) based on CLI and API, and RFT needs to understand java or. net and QTP require VB.
5. the loadrunner you mentioned is a performance testing tool, that is, testing software performance, such as multi-user operations, and writing code. The LR script supports the following languages: java, c, Visual Basic, vbscr extends pt. The default script generation language is C. What I want to say is that performance testing tools are not important. You need to master the performance testing methods.
2. I feel that you want to get started with automated testing. However, from the perspective of your questions, you may be blind. Let me briefly describe automated testing:
1. The concept of automated testing is to use various means to simulate manual operations, save labor testing costs, and ensure product testing quality.
2. If you want to learn automated software testing well, you don't just need to learn a few automated tools, but you can start with the tools,
First, tell you that the foundation of automated testing is
1) programming skills, including advanced languages and scripting languages. The scripting language is a master of advanced languages such as tcl, phython, and ruby, I am focusing on java. In addition, if you perform automated web Testing, web languages such as jsp, php, HTML, and CSS must be mastered.
2) Operating System skills; Because automated software testing is built on the operating system, skills must be good at using the operating system skills, such: registry, environment variable, handle, etc.
3) database knowledge should be good at using database knowledge for storage and management.
4) business knowledge, which is also the focus. The software business in your software industry needs to know how your software works.
5) quality and process management philosophy.
Then, your learning steps
1) You can start with tools and learn from specific projects. For example, java software interface testing (RFT, QTP java Plug-in, etc.) and web interface testing (QTP, selenium, etc), performance testing (RPT, loadrunner, etc ). But remember, learning its tools doesn't focus on simple use, but on how to use them to expand.
2) then, focus on learning the above basics, focusing on programming, and learning from the rest. By the way, the concept of automated testing is very similar to the concept of software design patterns, you can understand it.
3) then, I will learn how to develop my own automated testing framework. What is the framework? I cannot tell you clearly. I will recommend it to you.
NOTE: If there are no practical projects for automated testing, you 'd better start with the basics. Because the basics are good, the automated testing will get started quickly.
4 (the same is true for performance testing. You can start with a tool, but not limited to a tool. The most important thing in performance testing is the environment construction method and the analysis method for the test results, therefore, the focus of performance testing is on the analysis and implementation process, rather than the use of tools.
If you are interested in automated testing, you can send me short messages or emails. (Test_sunny@hotmail.com), have the opportunity to study together
Or, you can see the next my focus... the remaining full text>
Want to learn web automation testing, ruby? Python? Javascript? The web automation language scripting language recommended by all heroes.
Automated web testing:
Commercial tools:
The QTP language is vbscript.
Open Source:
Selenium supports ruby and python
Ruby also has watir and python has PAMIE, but watir is better than PAMIE.
What to learn depends on the big environment:
What do companies learn when using tools for testing?
If you are looking for a job, search for "test ruby" and "test python" on the job-seeking website. I will learn more about this job. Haha
In addition, javascript is required for web Front-end testing, and more or less ~