A apresentação está carregando. Por favor, espere

A apresentação está carregando. Por favor, espere

Jpf@fe.up.pt www.fe.up.pt/~jpf TQS - Teste e Qualidade de Software (Software Testing and Quality) Geração Automática de Casos de Teste com a Ferramenta.

Apresentações semelhantes


Apresentação em tema: "Jpf@fe.up.pt www.fe.up.pt/~jpf TQS - Teste e Qualidade de Software (Software Testing and Quality) Geração Automática de Casos de Teste com a Ferramenta."— Transcrição da apresentação:

1 jpf@fe.up.pt www.fe.up.pt/~jpf
TQS - Teste e Qualidade de Software (Software Testing and Quality) Geração Automática de Casos de Teste com a Ferramenta EclipsePro (Problema dos Extensos) João Pascoal Faria

2 Invocação do gerador

3 Resultados do gerador Projecto e classes gerados automati-camente

4 Casos de teste gerados automaticamente (1)
class ExtensosTest { .... public void testNumExt_1() throws Exception { int n = ; String result = Extensos.NumExt(n); // add test code here assertEquals("NOVECENTOS E NOVENTA E NOVE MILHÕES NOVECENTOS E NOVENTA E NOVE MIL NOVECENTOS E NOVENTA E NOVE", result); fail("unverified"); } public void testNumExt_2() throws Exception { int n = 0; assertEquals("ZERO", result); public void testNumExt_3() throws Exception { int n = ; assertEquals("UM MILHÃO", result); ... public void testNumExt_4() throws Exception { int n = 1000; String result = Extensos.NumExt(n); // add test code here assertEquals("MIL", result); fail("unverified"); } public void testNumExt_5() throws Exception { int n = 100; assertEquals("CEM", result); public void testNumExt_6() throws Exception { int n = 200; assertEquals("DUZENTOS", result);

5 Casos de teste gerados automaticamente (2)
... public void testNumExt_7() throws Exception { int n = 20; String result = Extensos.NumExt(n); // add test code here assertEquals("VINTE", result); fail("unverified"); } public void testNumExt_8() throws Exception { int n = ; assertEquals("NOVECENTOS E NOVENTA E NOVE MIL NOVECENTOS E NOVENTA E NOVE", result); public void testNumExt_9() throws Exception { int n = 999; assertEquals("NOVECENTOS E NOVENTA E NOVE", result); ... public void testNumExt_10() throws Exception { int n = 99; String result = Extensos.NumExt(n); // add test code here assertEquals("NOVENTA E NOVE", result); fail("unverified"); } public void testNumExt_11() throws Exception { int n = 199; assertEquals("CENTO E NOVENTA E NOVE", result); public void testNumExt_12() throws Exception { int n = 21; assertEquals("VINTE E UM", result);

6 Completar código gerado automaticamente
Comentar as instruções fail("unverified"); ficando // fail("unverified"); ou então alterar preferências antes de gerar Substituir junit.textui.TestRunner.run(ExtensosTest.class); por junit.swingui.TestRunner.run(ExtensosTest.class); Todos os casos de teste passam!

7 Grau de cobertura dos casos de teste gerados
não testou valores fora da gama e lançamento de excepções (por defeito só testa se excepção for declarada no cabeçalho do método) não testou milhões compostos com "E" não testou milhares compostos com "E" não testou dezenas exactas acima de 20

8 Geração de casos de teste para as excepções
public void testNumExt_13() throws Exception { int n = ; try { String result = Extensos.NumExt(n); fail("The exception java.lang.IllegalArgumentException should have been thrown."); } catch (java.lang.IllegalArgumentException exception) { if (!exception.getClass().getName().equals( "java.lang.IllegalArgumentException")) } public void testNumExt_14() throws Exception { int n = -1; Alterar cabeçalho do método NumExt acrescentando throws IllegalArgumentException Voltar a gerar os casos de teste automaticamente Aparecem 2 novos casos de teste

9 Como funciona a geração automática? (1)
"For each target method, the test generator 1. generates a list of values for the fixture (if the target method is an instance method) and each of the arguments, The test generator uses a number of heuristics to generate a list of values for a given argument. First, it analyzes the target method to try to determine how the parameter is used within the method and see whether that tells it anything about what values to use. For example, if an integer parameter is used in a switch statement, then it would use each of the values explicitly listed in non-empty case labels as well as some value that isn’t in any of the case labels. If it can’t determine anything from analyzing the method, then it looks to see if the type of the parameter is well known. This includes primitive types as well as several non-primitive types such as String. For well known types, there is a list of default values. For other classes of objects, as well as for test fixtures, it looks for zero-argument static accessor methods, constructors, and multi-argument static accessor methods, in that order, generating values for their arguments as necessary. 2. determines which combinations of values to use to invoke the method, The number of combinations of all possible values for fixtures and arguments is usually too high to be practical, so the test generator uses rules for choosing a reasonable number of those combinations.

10 Como funciona a geração automática? (2)
3. computes the result of invoking the method, Then, for each combination, the test generator computes the expected result of the method. This can either be a value, if the method returns normally, nothing, if the method has a return type of void, or an exception if the method throws an exception. 4. figures out how to validate the result, If an exception is thrown, it is assumed that the method should throw an exception and the test method will be written to verify that the exception is thrown. If the method returns a value, then the test generator determines how to test the returned value. Some types can be checked directly, while other types require invoking accessing methods or fields to determine the state of the object. If the method does not return a value, then the state of the fixture is tested instead. 5. generates one test method for each combination of values. Once we know the test fixture, argument values, and validation steps for each test method, generating the code for the test method is quite straightforward. The input values and expected results are also shown in the JUnit Test Case Outline view " (source: product documentation)

11 Links úteis www.instantiations.com
tem ferramenta comercial EclipsePro Test e Audit de análise de cobertura de código Java, geração automática de casos de teste, métricas, auditoria ao código, integrável no Eclipse, que pode ser experimentada gratuitamente (instalar a versão mais completa


Carregar ppt "Jpf@fe.up.pt www.fe.up.pt/~jpf TQS - Teste e Qualidade de Software (Software Testing and Quality) Geração Automática de Casos de Teste com a Ferramenta."

Apresentações semelhantes


Anúncios Google