SlideShare una empresa de Scribd logo
Assertion 
www.mentoringit.com.mx
Los assertion en Java son afirmaciones que nosotros podemos hacer en código y permiten realizar pruebas sobre escenarios reales de ejecución. 
Fueron agregados a java desde la versión 1.4. 
Los assertion se pueden habilitar y deshabilitar desde los argumentos de ejecución de nuestra aplicación. 
Los assertion contienen como parámetro una expresión booleana que siempre debe ser true para que el assertion se cumpla, en caso de que no se cumpla el assertion se lanza un AssertionError. 
www.mentoringit.com.mx
Primera forma para declarar un assert. assert Expression1 ; 
Donde Expression1 es una expresión que devuelve un valor booleano. 
Cuando se ejecuta el código con el assertion declarado arriba se evalúa Expression1 y si esta devuelve false, entonces el sistema lanza un AssertionError sin detalles del error. 
Segunda forma para declarar un assert. 
assert Expression1 : Expression2 ; 
Donde 
Expression1 : es una expresión booleana. 
Expression2 : es una expresión con descripción adicional del error y esta expresión se pasa al constructor de AssertionError el cual espera un String en el constructor. 
www.mentoringit.com.mx
Para habilitar los assertions en java se pueden ejecutar las aplicaciones de las siguientes formas: 
Habilitar los assertions para el programa BatTutor solo en el paquete com.wombat.fruitbat y sus subpaquetes. 
java -ea:com.wombat.fruitbat... BatTutor 
Habilitar los assertions para el programa BatTutor solo en el paquete fruitbat pero deshabilitadas para la clase BrickBat. 
java -ea:com.wombat.fruitbat... -da:com.wombat.fruitbat.Brickbat BatTutor 
Habilitar y deshabilitar los assertions para las clases de sistema. 
java -esa -ea:com.wombat.fruitbat... 
java -dsa -ea:com.wombat.fruitbat... 
www.mentoringit.com.mx
No utilizar assertion para verificar argumentos de métodos públicos. 
No utilizar assertion para realizar algún trabajo que la aplicación realizara en tiempo de ejecución. 
Los assertion por default están deshabilitados. 
En java 1.3 los assert aun no existían así que es permitido en esta versión de java utilizar assert como identificador, sin embargo se muestran warnings donde se estén utilizando al momento de compilar. 
En java 1.4 o superior assert no esta permitido como identificador, en caso de que existan en el código, un error es enviado al momento de compilar. 
www.mentoringit.com.mx

Más contenido relacionado

Último

Uso de las TIC en la vida cotidiana .
Uso de las TIC en la vida cotidiana       .Uso de las TIC en la vida cotidiana       .
Uso de las TIC en la vida cotidiana .itzyrivera61103
 
Bloque 1 _ Lectura base - Sistemas Distribuidos
Bloque 1 _ Lectura base - Sistemas DistribuidosBloque 1 _ Lectura base - Sistemas Distribuidos
Bloque 1 _ Lectura base - Sistemas DistribuidosLuisAntonioLopezGome
 
Presentacion y Extension de tema para Blogger.pptx
Presentacion y Extension de tema para Blogger.pptxPresentacion y Extension de tema para Blogger.pptx
Presentacion y Extension de tema para Blogger.pptxTaim11
 
HerramientasInformaticas ¿Que es? - ¿Para que sirve? - Recomendaciones - Comp...
HerramientasInformaticas ¿Que es? - ¿Para que sirve? - Recomendaciones - Comp...HerramientasInformaticas ¿Que es? - ¿Para que sirve? - Recomendaciones - Comp...
HerramientasInformaticas ¿Que es? - ¿Para que sirve? - Recomendaciones - Comp...Kevin Serna
 
Introducción a la robótica con arduino..pptx
Introducción a la robótica con arduino..pptxIntroducción a la robótica con arduino..pptx
Introducción a la robótica con arduino..pptxJohanna4222
 
Estudio de la geometría analitica. Pptx.
Estudio de la geometría analitica. Pptx.Estudio de la geometría analitica. Pptx.
Estudio de la geometría analitica. Pptx.sofiasonder
 
taller de tablas en word para estudiantes de secundaria
taller de tablas en word para estudiantes de secundariataller de tablas en word para estudiantes de secundaria
taller de tablas en word para estudiantes de secundariaandresingsiseo
 
proyectos_social_y_socioproductivos _mapas_conceptuales
proyectos_social_y_socioproductivos _mapas_conceptualesproyectos_social_y_socioproductivos _mapas_conceptuales
proyectos_social_y_socioproductivos _mapas_conceptualesssuserbe0d1c
 
editorial de informática de los sueños.docx
editorial de informática de los sueños.docxeditorial de informática de los sueños.docx
editorial de informática de los sueños.docxssusere34b451
 
Inteligencia Artificial para usuarios nivel inicial
Inteligencia Artificial para usuarios nivel inicialInteligencia Artificial para usuarios nivel inicial
Inteligencia Artificial para usuarios nivel inicialEducática
 
Pons, A. - El desorden digital - guia para historiadores y humanistas [2013].pdf
Pons, A. - El desorden digital - guia para historiadores y humanistas [2013].pdfPons, A. - El desorden digital - guia para historiadores y humanistas [2013].pdf
Pons, A. - El desorden digital - guia para historiadores y humanistas [2013].pdffrank0071
 
3°ð_¦_â_¾ï¸_S34 PLAN DARUKEL DIDÃ_CTICA 23-24.docx
3°ð_¦_â_¾ï¸_S34 PLAN DARUKEL DIDÃ_CTICA 23-24.docx3°ð_¦_â_¾ï¸_S34 PLAN DARUKEL DIDÃ_CTICA 23-24.docx
3°ð_¦_â_¾ï¸_S34 PLAN DARUKEL DIDÃ_CTICA 23-24.docxwerito139410
 
lenguaje algebraico.pptx álgebra, trigonometria
lenguaje algebraico.pptx álgebra, trigonometrialenguaje algebraico.pptx álgebra, trigonometria
lenguaje algebraico.pptx álgebra, trigonometriasofiasonder
 
¡Mira mi nuevo diseño hecho en Canva!.pdf
¡Mira mi nuevo diseño hecho en Canva!.pdf¡Mira mi nuevo diseño hecho en Canva!.pdf
¡Mira mi nuevo diseño hecho en Canva!.pdf7adelosriosarangojua
 
PRÁCTICAS DEL MÓDULO I Y II DE EDUCACIÓN Y SOCIEDAD.docx
PRÁCTICAS DEL MÓDULO I Y II DE EDUCACIÓN Y SOCIEDAD.docxPRÁCTICAS DEL MÓDULO I Y II DE EDUCACIÓN Y SOCIEDAD.docx
PRÁCTICAS DEL MÓDULO I Y II DE EDUCACIÓN Y SOCIEDAD.docxencinasm992
 
JORNADA INTELIGENCIA ARTIFICIAL Y REALIDAD VIRTUAL
JORNADA INTELIGENCIA ARTIFICIAL Y REALIDAD VIRTUALJORNADA INTELIGENCIA ARTIFICIAL Y REALIDAD VIRTUAL
JORNADA INTELIGENCIA ARTIFICIAL Y REALIDAD VIRTUALGuadalinfoHuscarGuad
 
herramientas informaticas mas utilizadas
herramientas informaticas mas utilizadasherramientas informaticas mas utilizadas
herramientas informaticas mas utilizadaspqeilyn0827
 
Sistemas distribuidos de redes de computadores en un entorno virtual de apren...
Sistemas distribuidos de redes de computadores en un entorno virtual de apren...Sistemas distribuidos de redes de computadores en un entorno virtual de apren...
Sistemas distribuidos de redes de computadores en un entorno virtual de apren...Luis Fernando Uribe Villamil
 
Gestión de concurrencia y bloqueos en SQL Server
Gestión de concurrencia y bloqueos en SQL ServerGestión de concurrencia y bloqueos en SQL Server
Gestión de concurrencia y bloqueos en SQL ServerRobertoCarrancioFern
 
manual-de-oleohidraulica-industrial-vickers.pdf
manual-de-oleohidraulica-industrial-vickers.pdfmanual-de-oleohidraulica-industrial-vickers.pdf
manual-de-oleohidraulica-industrial-vickers.pdfprofmartinsuarez
 

Último (20)

Uso de las TIC en la vida cotidiana .
Uso de las TIC en la vida cotidiana       .Uso de las TIC en la vida cotidiana       .
Uso de las TIC en la vida cotidiana .
 
Bloque 1 _ Lectura base - Sistemas Distribuidos
Bloque 1 _ Lectura base - Sistemas DistribuidosBloque 1 _ Lectura base - Sistemas Distribuidos
Bloque 1 _ Lectura base - Sistemas Distribuidos
 
Presentacion y Extension de tema para Blogger.pptx
Presentacion y Extension de tema para Blogger.pptxPresentacion y Extension de tema para Blogger.pptx
Presentacion y Extension de tema para Blogger.pptx
 
HerramientasInformaticas ¿Que es? - ¿Para que sirve? - Recomendaciones - Comp...
HerramientasInformaticas ¿Que es? - ¿Para que sirve? - Recomendaciones - Comp...HerramientasInformaticas ¿Que es? - ¿Para que sirve? - Recomendaciones - Comp...
HerramientasInformaticas ¿Que es? - ¿Para que sirve? - Recomendaciones - Comp...
 
Introducción a la robótica con arduino..pptx
Introducción a la robótica con arduino..pptxIntroducción a la robótica con arduino..pptx
Introducción a la robótica con arduino..pptx
 
Estudio de la geometría analitica. Pptx.
Estudio de la geometría analitica. Pptx.Estudio de la geometría analitica. Pptx.
Estudio de la geometría analitica. Pptx.
 
taller de tablas en word para estudiantes de secundaria
taller de tablas en word para estudiantes de secundariataller de tablas en word para estudiantes de secundaria
taller de tablas en word para estudiantes de secundaria
 
proyectos_social_y_socioproductivos _mapas_conceptuales
proyectos_social_y_socioproductivos _mapas_conceptualesproyectos_social_y_socioproductivos _mapas_conceptuales
proyectos_social_y_socioproductivos _mapas_conceptuales
 
editorial de informática de los sueños.docx
editorial de informática de los sueños.docxeditorial de informática de los sueños.docx
editorial de informática de los sueños.docx
 
Inteligencia Artificial para usuarios nivel inicial
Inteligencia Artificial para usuarios nivel inicialInteligencia Artificial para usuarios nivel inicial
Inteligencia Artificial para usuarios nivel inicial
 
Pons, A. - El desorden digital - guia para historiadores y humanistas [2013].pdf
Pons, A. - El desorden digital - guia para historiadores y humanistas [2013].pdfPons, A. - El desorden digital - guia para historiadores y humanistas [2013].pdf
Pons, A. - El desorden digital - guia para historiadores y humanistas [2013].pdf
 
3°ð_¦_â_¾ï¸_S34 PLAN DARUKEL DIDÃ_CTICA 23-24.docx
3°ð_¦_â_¾ï¸_S34 PLAN DARUKEL DIDÃ_CTICA 23-24.docx3°ð_¦_â_¾ï¸_S34 PLAN DARUKEL DIDÃ_CTICA 23-24.docx
3°ð_¦_â_¾ï¸_S34 PLAN DARUKEL DIDÃ_CTICA 23-24.docx
 
lenguaje algebraico.pptx álgebra, trigonometria
lenguaje algebraico.pptx álgebra, trigonometrialenguaje algebraico.pptx álgebra, trigonometria
lenguaje algebraico.pptx álgebra, trigonometria
 
¡Mira mi nuevo diseño hecho en Canva!.pdf
¡Mira mi nuevo diseño hecho en Canva!.pdf¡Mira mi nuevo diseño hecho en Canva!.pdf
¡Mira mi nuevo diseño hecho en Canva!.pdf
 
PRÁCTICAS DEL MÓDULO I Y II DE EDUCACIÓN Y SOCIEDAD.docx
PRÁCTICAS DEL MÓDULO I Y II DE EDUCACIÓN Y SOCIEDAD.docxPRÁCTICAS DEL MÓDULO I Y II DE EDUCACIÓN Y SOCIEDAD.docx
PRÁCTICAS DEL MÓDULO I Y II DE EDUCACIÓN Y SOCIEDAD.docx
 
JORNADA INTELIGENCIA ARTIFICIAL Y REALIDAD VIRTUAL
JORNADA INTELIGENCIA ARTIFICIAL Y REALIDAD VIRTUALJORNADA INTELIGENCIA ARTIFICIAL Y REALIDAD VIRTUAL
JORNADA INTELIGENCIA ARTIFICIAL Y REALIDAD VIRTUAL
 
herramientas informaticas mas utilizadas
herramientas informaticas mas utilizadasherramientas informaticas mas utilizadas
herramientas informaticas mas utilizadas
 
Sistemas distribuidos de redes de computadores en un entorno virtual de apren...
Sistemas distribuidos de redes de computadores en un entorno virtual de apren...Sistemas distribuidos de redes de computadores en un entorno virtual de apren...
Sistemas distribuidos de redes de computadores en un entorno virtual de apren...
 
Gestión de concurrencia y bloqueos en SQL Server
Gestión de concurrencia y bloqueos en SQL ServerGestión de concurrencia y bloqueos en SQL Server
Gestión de concurrencia y bloqueos en SQL Server
 
manual-de-oleohidraulica-industrial-vickers.pdf
manual-de-oleohidraulica-industrial-vickers.pdfmanual-de-oleohidraulica-industrial-vickers.pdf
manual-de-oleohidraulica-industrial-vickers.pdf
 

Destacado

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

Destacado (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Java desde cero assertions

  • 2. Los assertion en Java son afirmaciones que nosotros podemos hacer en código y permiten realizar pruebas sobre escenarios reales de ejecución. Fueron agregados a java desde la versión 1.4. Los assertion se pueden habilitar y deshabilitar desde los argumentos de ejecución de nuestra aplicación. Los assertion contienen como parámetro una expresión booleana que siempre debe ser true para que el assertion se cumpla, en caso de que no se cumpla el assertion se lanza un AssertionError. www.mentoringit.com.mx
  • 3. Primera forma para declarar un assert. assert Expression1 ; Donde Expression1 es una expresión que devuelve un valor booleano. Cuando se ejecuta el código con el assertion declarado arriba se evalúa Expression1 y si esta devuelve false, entonces el sistema lanza un AssertionError sin detalles del error. Segunda forma para declarar un assert. assert Expression1 : Expression2 ; Donde Expression1 : es una expresión booleana. Expression2 : es una expresión con descripción adicional del error y esta expresión se pasa al constructor de AssertionError el cual espera un String en el constructor. www.mentoringit.com.mx
  • 4. Para habilitar los assertions en java se pueden ejecutar las aplicaciones de las siguientes formas: Habilitar los assertions para el programa BatTutor solo en el paquete com.wombat.fruitbat y sus subpaquetes. java -ea:com.wombat.fruitbat... BatTutor Habilitar los assertions para el programa BatTutor solo en el paquete fruitbat pero deshabilitadas para la clase BrickBat. java -ea:com.wombat.fruitbat... -da:com.wombat.fruitbat.Brickbat BatTutor Habilitar y deshabilitar los assertions para las clases de sistema. java -esa -ea:com.wombat.fruitbat... java -dsa -ea:com.wombat.fruitbat... www.mentoringit.com.mx
  • 5. No utilizar assertion para verificar argumentos de métodos públicos. No utilizar assertion para realizar algún trabajo que la aplicación realizara en tiempo de ejecución. Los assertion por default están deshabilitados. En java 1.3 los assert aun no existían así que es permitido en esta versión de java utilizar assert como identificador, sin embargo se muestran warnings donde se estén utilizando al momento de compilar. En java 1.4 o superior assert no esta permitido como identificador, en caso de que existan en el código, un error es enviado al momento de compilar. www.mentoringit.com.mx